source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/applications/welcome/views/generic.map

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 2.7 KB
Line 
1{{"""
2this is an example of usage of google map
3the web2py action should be something like:
4
5def map():
6    return dict(
7      googlemap_key='...',
8      center_latitude = 41.878,
9      center_longitude = -87.629,
10      scale = 7,
11      maker = lambda point: A(row.id,_href='...')
12      points = db(db.point).select() where a points have latitute and longitude
13    )
14
15the corresponding views/defaut/map.html should be something like:
16
17    \{\{extend 'layout.html'\}\}
18    <center>\{\{include 'generic.map'\}\}</center>
19
20"""}}
21  <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key={{=googlemap_key}}" type="text/javascript"></script>
22    <script type="text/javascript">
23    //<![CDATA[
24    function load() {
25      if (GBrowserIsCompatible()) {
26        var map = new GMap2(document.getElementById("map"));
27        map.addControl(new GSmallMapControl());
28        map.addControl(new GMapTypeControl());
29        map.setCenter(new GLatLng({{=center_latitude}},
30           {{=center_longitude}}), {{=scale}});
31        // Create a base icon for all of our markers that specifies the
32        // shadow, icon dimensions, etc.
33        var baseIcon = new GIcon();
34        baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
35        baseIcon.iconSize = new GSize(20, 34);
36        baseIcon.shadowSize = new GSize(37, 34);
37        baseIcon.iconAnchor = new GPoint(9, 34);
38        baseIcon.infoWindowAnchor = new GPoint(9, 2);
39        baseIcon.infoShadowAnchor = new GPoint(18, 14);
40        var blueIcon = new GIcon();
41        blueIcon.image = "http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png";
42        blueIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
43        blueIcon.iconSize = new GSize(37, 34);
44        blueIcon.shadowSize = new GSize(37, 34);
45        blueIcon.iconAnchor = new GPoint(9, 34);
46        blueIcon.infoWindowAnchor = new GPoint(9, 2);
47        blueIcon.infoShadowAnchor = new GPoint(18, 14);
48
49        function createMarker(point, i, message) {
50           // Set up our GMarkerOptions object
51           if(i==0) markerOptions = { icon:blueIcon };
52           else markerOptions= {}
53           var marker = new GMarker(point, markerOptions);
54           GEvent.addListener(marker, "click", function() {
55             marker.openInfoWindowHtml(message);
56           });
57           return marker;
58        }
59        {{for point in points:}}{{if point.latitude and point.longitude:}}
60          var point = new GLatLng({{=point.latitude}},{{=point.longitude}});
61          map.addOverlay(createMarker(point, 0,
62            '{{=point.get('map_marker',maker(point))}}'));
63        {{pass}}{{pass}}
64     }
65    }
66    //]]>
67    </script>
68    <div id="map" style="width: 800px; height: 500px"></div>
69    <script>load();</script>
Note: See TracBrowser for help on using the repository browser.