X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Fgooglemaps%2Fstatic%2Fjs%2Fgooglemaps.js;fp=plugins%2Fgooglemaps%2Fstatic%2Fjs%2Fgooglemaps.js;h=e97d1f5f5bd7bca26434dd32d548b16a11fd6bad;hb=8c344999d6ee3b3a9172a1068a77c83af77a7aee;hp=0000000000000000000000000000000000000000;hpb=c84873b7b55121705ca5ec4d897194faadcb8408;p=myslice.git diff --git a/plugins/googlemaps/static/js/googlemaps.js b/plugins/googlemaps/static/js/googlemaps.js new file mode 100644 index 00000000..e97d1f5f --- /dev/null +++ b/plugins/googlemaps/static/js/googlemaps.js @@ -0,0 +1,248 @@ +/** + * Description: display a query result in a Google map + * Copyright (c) 2012-2013 UPMC Sorbonne Universite - INRIA + * License: GPLv3 + */ + +(function($){ + + var GoogleMaps = Plugin.extend({ + + init: function(options, element) + { + this._super(options, element); + + /* Member variables */ + // query status + this.received_all = false; + this.received_set = false; + this.in_set_buffer = Array(); + + /* XXX Events XXX */ + this.$element.on('show.Datatables', this.on_show); + // TODO in destructor + // $(window).unbind('Hazelnut'); + + /* Setup query and record handlers */ + this.listen_query(options.query_uuid); + this.listen_query(options.query_all_uuid, 'all'); + + /* GUI setup and event binding */ + this.initialize_map(); + }, // init + + /* PLUGIN EVENTS */ + + on_show: function() + { + google.maps.event.trigger(map, 'resize'); + }, // on_show + + /* GUI EVENTS */ + + /* GUI MANIPULATION */ + + /** + */ + initialize_map: function() + { + this.map = null; + this.markerCluster = null; + this.markers = []; + this.coords = new Array(); + + var myLatlng = new google.maps.LatLng(this.options.latitude, this.options.longitude); + var myOptions = { + zoom: this.options.zoom, + center: myLatlng, + mapTypeId: google.maps.MapTypeId.ROADMAP + } + + this.map = new google.maps.Map(document.getElementById("map"), myOptions); + this.infowindow = new google.maps.InfoWindow(); + }, // initialize_map + + /** + */ + new_record: function(record) + { + // get the coordinates + var latitude=get_value(record['latitude']); + var longitude=get_value(record['longitude']); + var hash = latitude + longitude; + + // check to see if we've seen this hash before + if(this.coords[hash] == null) { + // get coordinate object + var myLatlng = new google.maps.LatLng(latitude, longitude); + // store an indicator that we've seen this point before + this.coords[hash] = 1; + } else { + // add some randomness to this point 1500 = 100 meters, 15000 = 10 meters + var lat = latitude + (Math.random() -.5) / 1500; + var lng = longitude + (Math.random() -.5) / 1500; + + // get the coordinate object + var myLatlng = new google.maps.LatLng(lat, lng); + } + // If the node is attached to the slice, action will be Remove; else action will be add to slice + if (typeof(record['sliver']) != 'undefined') { + data.current_resources.push(record['urn']); + action="del"; + action_class="ui-icon-circle-minus"; + action_message="Remove from slice"; + }else{ + action="add"; + action_class="ui-icon-circle-plus"; + action_message="Add to slice"; + } + // XXX not working + if (!(record['latitude'])) { + return true; + } + + //jQuery(".map-button").click(button_click); + //if(jQuery.inArray(record, rows)>-1){ + var marker = new google.maps.Marker({ + position: myLatlng, + title: get_value(record['hostname']), + // This should be done by the rendering + content: '
Agent: ' + get_value(record['ip']) + ' (' + get_value(record['resource_hrn']) + ')
Platform: ' + get_value(record['platform'])+'