Created
June 16, 2015 15:29
-
-
Save jparbros/0c70a5bbc3f37bddcda8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module BoxBound | |
extend ActiveSupport::Concern | |
def get_bounds | |
curl = Curl::Easy.new | |
curl.url = 'http://cartografia.ife.org.mx/sige/ajax/get_searchv5' | |
curl.headers = {'Content-Type' => 'application/x-www-form-urlencoded'} | |
curl.http_post("e=6&q=#{section}&t=seccion&c=SECCION") | |
Yajl::Parser.parse(curl.body.split('|')[1]) | |
end | |
def multipolygon | |
@response ||= get_bounds | |
@response['valores'].first['geom'] | |
end | |
def bound_coords | |
@factory ||= GeoRuby::SimpleFeatures::GeometryFactory.new | |
@ewkt_parser ||= GeoRuby::SimpleFeatures::EWKTParser.new @factory | |
@ewkt_parser.parse multipolygon | |
@coords ||= @factory.geometry.geometries.first.rings.first.map {|point| [point.y, point.x]} | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript" charset="utf-8" async defer> | |
var map; | |
var sections = [<%= @report.near_boxes.map{|near_box| "'#{near_box.section}'"}.join(',').html_safe %>]; | |
function initialize() { | |
var mapOptions = { | |
zoom: 14, | |
center: new google.maps.LatLng(<%= @geographic_center.first %>, <%= @geographic_center.last %>), | |
mapTypeId: google.maps.MapTypeId.ROADMAP, | |
styles: [ | |
{ | |
"featureType":"administrative", | |
"elementType":"labels", | |
"stylers":[ | |
{ | |
"visibility":"on" | |
} | |
] | |
}, | |
{ | |
"featureType":"road", | |
"stylers":[ | |
{ | |
"visibility":"on" | |
} | |
] | |
}, | |
{ | |
"featureType":"road.highway", | |
"stylers":[ | |
{ | |
"visibility":"off" | |
} | |
] | |
}, | |
{ | |
"featureType":"poi", | |
"stylers":[ | |
{ | |
"visibility":"off" | |
} | |
] | |
}, | |
{ | |
"featureType":"water", | |
"elementType":"labels", | |
"stylers":[ | |
{ | |
"visibility":"off" | |
} | |
] | |
}, | |
{ | |
"featureType": "landscape", | |
"elementType": "geometry", | |
"stylers": [ | |
{ "visibility": "on" }, | |
{ "color": "#ffffff" } | |
] | |
} | |
] | |
}; | |
map = new google.maps.Map(document.getElementById('report-map'), mapOptions); | |
var boxes_bounds = [<%= @boxes_bound_coords.map do |box_bound| | |
"[" + box_bound.map do |coords| | |
"new google.maps.LatLng(#{coords.first}, #{coords.last})" | |
end.join(',') + "]" | |
end.join(',').html_safe %>] | |
var color_bound = ['#FF0000', '#00FF00', '#0000FF', '#FFFF00', '#FF00FF'] | |
for (var i = 0; i < boxes_bounds.length; i++) { | |
seccionPolygon = new google.maps.Polygon({ | |
paths: boxes_bounds[i], | |
strokeColor: '#CCCCCC', | |
strokeOpacity: 0.8, | |
strokeWeight: 2, | |
fillColor: color_bound[i], | |
fillOpacity: 0.15 | |
}); | |
seccionPolygon.setMap(map); | |
} | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment