Changeset 396

Show
Ignore:
Timestamp:
07/13/06 10:33:29
Author:
piv
Message:

added map widget, ...

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • qPloneGoogleMaps/trunk/README.txt

    r395 r396  
    11qPloneGoogleMaps 
     2 
     3Authors 
     4 
     5  * Myroslav Opyr 
     6   
     7  * Vitaliy Podoba 
     8     
  • qPloneGoogleMaps/trunk/TODO.txt

    r395 r396  
    66#  * folder view 
    77 
    8    * marker functionality 
     8#   * marker functionality 
     9 
     10#   * map field and widget 
     11 
     12#   * navigation portlet view (turn on/off overlay functionality) 
  • qPloneGoogleMaps/trunk/__init__.py

    r395 r396  
    88 
    99from Products.qPloneGoogleMaps.config import * 
     10 
     11from Products.validation import validation 
     12 
     13from Products.qPloneGoogleMaps.validator import MapFieldValidator 
     14validation.register(MapFieldValidator('isLocation')) 
    1015 
    1116allow_module('Products.qPloneGoogleMaps.config') 
  • qPloneGoogleMaps/trunk/content/Map.py

    r395 r396  
    88  from Products.Archetypes.public import * 
    99 
    10 from Products.ATContentTypes.content.base import ATCTFolder 
     10from Products.ATContentTypes.content.base import ATCTFolder, updateActions 
    1111from Products.ATContentTypes.content.schemata import finalizeATCTSchema 
    1212 
    13 from Products.CMFPlone.interfaces.NonStructuralFolder import INonStructuralFolder 
     13#from Products.CMFPlone.interfaces.NonStructuralFolder import INonStructuralFolder 
    1414 
    15 from Products.validation.validators.RangeValidator import RangeValidator 
    16 from Products.validation.config import validation 
    17 from Products.validation import V_REQUIRED 
    18  
     15from Products.qPloneGoogleMaps.field import * 
    1916from Products.qPloneGoogleMaps.config import * 
    20  
    21 validation.register(RangeValidator('checkLatitude', 
    22                                    minval=-90.0, maxval=90.0)) 
    23 validation.register(RangeValidator('checkLongitude', 
    24                                    minval=-180.0, maxval=180.0)) 
    2517 
    2618zoom_vocaburary = range(18) 
     
    2820 
    2921MapSchema = ATCTFolder.schema.copy() + Schema(( 
     22    MapField('location', 
     23        default=None, 
     24        required=True, 
     25        validators=('isLocation',), 
     26        widget=MapWidget( 
     27            label='Map Center', 
     28            label_msgid='label_map_center', 
     29            description='Here you can choose map center point on the map by mouse clicking', 
     30            description_msgid='help_map_center', 
     31            i18n_domain='googlemaps', 
     32        ) 
     33    ), 
     34 
     35    StringField('auto', 
     36        vocabulary=('None', 'Zoom', 'Center', 'Full'), 
     37        default='None', 
     38        widget=SelectionWidget( 
     39            label='Auto Control', 
     40            label_msgid='label_auto_control', 
     41            description_msgid='help_auto_control', 
     42            i18n_domain='googlemaps', 
     43            format = 'radio', 
     44        ) 
     45    ), 
     46 
    3047    IntegerField('height', 
    3148        default="480", 
     
    3653            description_msgid='help_height', 
    3754            i18n_domain='googlemaps', 
    38         ) 
    39     ), 
    40  
    41     FloatField('latitude', 
    42         required=True, 
    43         validators=(('checkLatitude', V_REQUIRED),), 
    44         widget=DecimalWidget( 
    45             label='Center latitude', 
    46             label_msgid='label_center_latitude', 
    47             description_msgid='help_center_latitude', 
    48             i18n_domain='googlemaps', 
    49             size=12, 
    50         ) 
    51     ), 
    52  
    53     FloatField('longitude', 
    54         required=True, 
    55         validators=(('checkLongitude', V_REQUIRED),), 
    56         widget=DecimalWidget( 
    57             label='Center longitude', 
    58             label_msgid='label_center_longitude', 
    59             description_msgid='help_center_longitude', 
    60             i18n_domain='googlemaps', 
    61             size=12, 
    6255        ) 
    6356    ), 
     
    8679 
    8780    StringField('mapType', 
    88         vocabulary=('map', 'satellite'), 
    89         default='map', 
     81        vocabulary=('map', 'satellite', 'hybrid'), 
     82        default='hybrid', 
    9083        widget=SelectionWidget( 
    9184            label='Map Type', 
     
    138131 
    139132    # Get the standard actions (tabs) 
    140     #actions = ATCTContent.actions 
     133    actions = updateActions(ATCTFolder, 
     134        ({'id'          : 'edit', 
     135          'name'        : 'Edit', 
     136          'action'      : 'string:${object_url}/map_edit', 
     137          'permissions' : (ModifyPortalContent,) 
     138         }, 
     139        ) 
     140    ) 
    141141 
    142142    #__implements__ = (ATCTFolder.__implements__, INonStructuralFolder) 
     
    152152    security.declareProtected(View, 'geoLocation') 
    153153    def geoLocation(self): 
    154         return (self.getLatitude(), self.getLongitude()) 
     154        """ Return geolocation tuple """ 
     155        return self.location 
    155156 
    156157    security.declareProtected(View, 'getOverlayMarkers') 
  • qPloneGoogleMaps/trunk/content/Marker.py

    r395 r396  
    1010from Products.ATContentTypes.content.document import ATDocumentSchema 
    1111from Products.ATContentTypes.content.document import ATDocument 
    12 #from Products.ATContentTypes.content.schemata import ATContentTypeSchema 
    1312from Products.ATContentTypes.content.schemata import finalizeATCTSchema 
    1413 
    15 #from Products.CMFPlone.interfaces.NonStructuralFolder import INonStructuralFolder 
    16  
    17 from Products.validation.validators.RangeValidator import RangeValidator 
    18 from Products.validation.config import validation 
    19 from Products.validation import V_REQUIRED 
    20  
     14from Products.qPloneGoogleMaps.field import * 
    2115from Products.qPloneGoogleMaps.config import * 
    2216 
    23 validation.register(RangeValidator('checkLatitude', 
    24                                    minval=-90.0, maxval=90.0)) 
    25 validation.register(RangeValidator('checkLongitude', 
    26                                    minval=-180.0, maxval=180.0)) 
    27  
    2817MarkerSchema = ATDocumentSchema.copy() + Schema(( 
    29     FloatField('latitude', 
     18    MapField('location', 
     19        default=None, 
    3020        required=True, 
    31         validators=(('checkLatitude', V_REQUIRED),), 
    32         widget=DecimalWidget( 
    33             label='Latitude', 
    34             label_msgid='label_latitude', 
    35             description_msgid='help_latitude', 
     21        validators=('isLocation',), 
     22        widget=MapWidget( 
     23            label='Marker Location', 
     24            label_msgid='label_marker_center', 
     25            description='Here you can choose marker location on the map by mouse clicking', 
     26            description_msgid='help_marker_center', 
    3627            i18n_domain='googlemaps', 
    37             size=12, 
    38         ) 
    39     ), 
    40  
    41     FloatField('longitude', 
    42         required=True, 
    43         validators=(('checkLongitude', V_REQUIRED),), 
    44         widget=DecimalWidget( 
    45             label='Longitude', 
    46             label_msgid='label_longitude', 
    47             description_msgid='help_longitude', 
    48             i18n_domain='googlemaps', 
    49             size=12, 
    5028        ) 
    5129    ), 
     
    9270    security.declareProtected(View, 'geoLocation') 
    9371    def geoLocation(self): 
    94         return (self.getLatitude(), self.getLongitude()
     72        return self.getLocation(
    9573 
    9674registerType(Marker, PROJECTNAME) 
  • qPloneGoogleMaps/trunk/content/Overlay.py

    r395 r396  
    6969        """ Get object or brains with geolocation properties from source object """ 
    7070        container = self.getSource() 
    71         contentsMethod = container.getFolderContents 
    72         if container.portal_type == 'Topic': contentsMethod = container.queryCatalog 
    73         return [el for el in contentsMethod() if el.geoLocation] 
     71        if container and container.portal_type: 
     72            contentsMethod = container.getFolderContents 
     73            if container.portal_type == 'Topic': contentsMethod = container.queryCatalog 
     74            return [el for el in contentsMethod() if el.geoLocation] 
     75        return [] 
    7476 
    7577registerType(Overlay, PROJECTNAME) 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/map_view.pt

    r395 r396  
    99            tal:attributes="src string:http://maps.google.com/maps?file=api&v=2&key=${key}"> 
    1010    </script> 
    11     <span tal:replace="structure python:here.maps_markers(longlat=here.getOverlayMarkers(), node='map', controls=here.getMapControl(), loc=here.geoLocation(), typeControls=here.getTypeControl(), overviewControls=here.getOverviewControl(), events=True, maptype=here.getMapType(), color=False, zoom=here.getZoom(), mapevents=True)" /> 
     11    <span tal:replace="structure python:here.maps_markers(longlat=here.getOverlayMarkers(), node='map', controls=here.getMapControl(), loc=here.geoLocation(), typeControls=here.getTypeControl(), overviewControls=here.getOverviewControl(), events=True, maptype=here.getMapType(), color=False, zoom=here.getZoom(), mapevents=True, auto=here.getAuto())" /> 
    1212  </metal:block> 
    1313</head> 
     
    3232    </p> 
    3333 
    34     <!-- gmarker  
    35     <ul> 
    36     <tal:gmarker tal:repeat="marker python: here.objectValues(['GMarker'])"> 
    37       <li id="" tal:attributes="id string:marker_link_${repeat/marker/number}"> 
    38         <a href="javascript:void(0)" onclick="this.blur()" tal:content="marker/pretty_title_or_id"> 
    39           Gmarker title 
    40         </a> 
    41       </li> 
    42     </tal:gmarker> 
    43     </ul> 
    44  
    45     <tal:gmarker tal:repeat="marker python: here.objectValues(['GMarker'])"> 
    46       <div id="" style="display: none;" 
    47            tal:attributes="id string:marker_html_${repeat/marker/number}"> 
    48         <div style="width: 290px;"> 
    49           <div class="documentActions"> 
    50             <a href="" tal:condition="marker/url" 
    51                tal:attributes="href marker/url" 
    52                i18n:translate="" i18n:domain="plone"> 
    53                Link 
    54             </a> 
    55           </div> 
    56  
    57       <h1 class="documentFirstHeading"> 
    58         <a href="" tal:content="marker/pretty_title_or_id" 
    59            tal:attributes="href marker/absolute_url"> 
    60           Title or id 
    61         </a> 
    62       </h1> 
    63  
    64           <img src="" style="float: left; margin: 5px;" 
    65                tal:condition="marker/imageurl" 
    66                tal:attributes="src marker/imageurl" /> 
    67  
    68           <div class="documentDescription" 
    69              tal:content="marker/Description" 
    70              tal:condition="marker/Description"> 
    71               Description 
    72           </div> 
    73  
    74           <div class="address" 
    75              tal:content="marker/address" 
    76              tal:condition="marker/address"> 
    77             address 
    78           </div> 
    79  
    80           <div class="phone" 
    81              tal:content="marker/phone" 
    82              tal:condition="marker/phone"> 
    83             phone 
    84           </div> 
    85  
    86           <div style="clear: both;" tal:condition="marker/getText" 
    87                tal:content="structure marker/getText"> 
    88              Body Text 
    89           </div> 
    90  
    91         </div> 
    92       </div> 
    93     </tal:gmarker>--> 
    94  
    9534    <div id="map" style="position: relative; height: 480px;" 
    9635         tal:define="height here/getHeight" 
     
    10241</body> 
    10342</html> 
    104      
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/maps_markers.py

    r395 r396  
    55##bind script=script 
    66##bind subpath=traverse_subpath 
    7 ##parameters= longlat=[], node, controls='nothing', maptype='G_NORMAL_MAP', overviewControls=None, typeControls=None, events=False, color='default', zoom=6, loc=(37.4419, -122.1419), marker=False, mapevents=None 
     7##parameters= longlat=[], node, controls='nothing', maptype='hybrid', overviewControls=None, typeControls=None, events=False, color='default', zoom=None, loc=(37.4419, -122.1419), mapevents=None, auto='None' 
    88##title= 
    99## 
     
    2727 
    2828if maptype == 'satellite': maptype = 'G_SATELLITE_MAP' 
     29elif maptype == 'map': maptype = 'G_NORMAL_MAP' 
     30else: maptype = 'G_HYBRID_MAP' 
    2931 
    3032if (not color) and longlat: 
    3133    lat = [float(e.geoLocation[0]) for el in longlat.values() for e in el] 
    3234    lon = [float(e.geoLocation[1]) for el in longlat.values() for e in el] 
    33     sMarkers = "\n".join(["""addMarker(%f, %f, "%s", "%s", "%s", "%s");""" % (float(e.geoLocation[0]), float(e.geoLocation[1]), e.Title, e.getURL(), processDesc(e.Description), el) for el, value in longlat.items() for e in value]) 
     35    sMarkers = "\n".join(["""addMarker(%f, %f, "%s", "%s/view", "%s", "%s");""" % (float(e.geoLocation[0]), float(e.geoLocation[1]), e.Title, e.getURL(), processDesc(e.Description), el) for el, value in longlat.items() for e in value]) 
    3436elif longlat: 
    3537    lat = [float(el.geoLocation[0]) for el in longlat] 
    3638    lon = [float(el.geoLocation[1]) for el in longlat] 
    37     sMarkers = "\n".join(["""addMarker(%f, %f, "%s", "%s", "%s", "%s");""" % (float(el.geoLocation[0]), float(el.geoLocation[1]), el.Title, el.getURL(), processDesc(el.Description), color) for el in longlat]) 
     39    sMarkers = "\n".join(["""addMarker(%f, %f, "%s", "%s/view", "%s", "%s");""" % (float(el.geoLocation[0]), float(el.geoLocation[1]), el.Title, el.getURL(), processDesc(el.Description), color) for el in longlat]) 
    3840 
    3941if controls == 'large': sControls += "map.addControl(new GLargeMapControl());" 
     
    6567      }; 
    6668      GEvent.addListener(map, 'click', listener);""" % sMarkerForm 
     69 
    6770if events: 
    6871    sMarkerEvents = """ 
    6972      var f = function(){marker.openInfoWindowHtml(%s, opt);}; 
    7073      GEvent.addListener(marker, 'click', f);\n""" % sInfoWindow 
    71 if not marker and lon and lat: 
     74 
     75if lon and lat and auto != 'None': 
    7276    sDefaults = """ 
    73 map.setCenter(new GLatLng(%f, %f), map.getBoundsZoomLevel(new GLatLngBounds(new GLatLng(%f, %f), new GLatLng(%f, %f)))); 
    74 map.savePosition();""" % ((min(lat)+max(lat))/2, (min(lon)+max(lon))/2, min(lat), min(lon), max(lat), max(lon)) 
     77var centerPoint = new GLatLng(%f, %f), 
     78autoZoom = map.getBoundsZoomLevel(new GLatLngBounds(new GLatLng(%f, %f), new GLatLng(%f, %f))); 
     79""" % ((min(lat)+max(lat))/2, (min(lon)+max(lon))/2, min(lat), min(lon), max(lat), max(lon)) 
     80    if auto == 'Zoom': sDefaults += """map.setZoom(autoZoom);""" 
     81    elif auto == 'Center': sDefaults += """map.setCenter(centerPoint);""" 
     82    elif auto == 'Full': sDefaults += """map.setCenter(centerPoint, autoZoom);""" 
     83    sDefaults += """map.savePosition();""" 
     84 
     85if not zoom: zoom = 6 
    7586 
    7687return """ 
    7788<script type="text/javascript"> 
    7889//<![CDATA[ 
     90 
     91function registerUnloadFunction(func){ 
     92  if (window.addEventListener) window.addEventListener("unload", func, false); 
     93  else if (window.attachEvent) window.attachEvent("onunload", func); 
     94}; 
    7995 
    8096function onLoadMap(){ 
     
    8399    var map = new GMap2(document.getElementById('%(node)s')); 
    84100    %(controls)s 
    85     map.setCenter(new GLatLng(%(lt)f, %(ln)f), %(zoom)s, G_HYBRID_MAP) 
     101    map.setCenter(new GLatLng(%(lt)f, %(ln)f), %(zoom)s, %(maptype)s); 
    86102    var opt = map.getInfoWindow(); 
    87103    opt.maxWidth = 400; 
     
    107123  else window.alert("Google maps aren't compatible with current Browser."); 
    108124}; 
     125 
    109126registerPloneFunction(onLoadMap); 
     127registerUnloadFunction(GUnload); 
     128 
    110129//]]> 
    111130</script> 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/maps_view.pt

    r395 r396  
    1010    </script> 
    1111    <span tal:define="brain python:here.portal_catalog(path='/'.join(here.getPhysicalPath())); 
    12                       longlat python:test(len(brain)==1 and brain[0].geoLocation, brain, [])" 
    13           tal:replace="structure python:here.maps_markers(longlat, node='map', events=True, controls='large', typeControls=True, overviewControls=True)" /> 
     12                      longlat python:test(len(brain)==1 and brain[0].portal_type != 'Map' and brain[0].geoLocation, brain, [])" 
     13          tal:replace="structure python:here.maps_markers(longlat, node='map', events=True, controls='large', typeControls=True, overviewControls=True, zoom=6, loc=longlat[0].geoLocation)" /> 
    1414  </metal:block> 
    1515</head> 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/marker_view.pt

    r395 r396  
    99            tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${key}"> 
    1010    </script> 
    11     <span tal:replace="structure python:here.maps_markers(here.portal_catalog(path='/'.join(here.getPhysicalPath())), node='map', events=True, loc=here.geoLocation(), controls='large', typeControls=True, overviewControls=True, marker=True, color=here.getColor())" /> 
     11    <span tal:replace="structure python:here.maps_markers(here.portal_catalog(path='/'.join(here.getPhysicalPath())), node='map', events=True, loc=here.geoLocation(), controls='large', typeControls=True, overviewControls=True, color=here.getColor(), zoom=6)" /> 
    1212 
    1313  </metal:block> 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/overlay_view.pt

    r395 r396  
    99            tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${key}"> 
    1010    </script> 
    11     <span tal:replace="structure python:here.maps_markers(here.getMarkers(), node='map', events=True, color=here.getMarkersColor(), loc=here.geoLocation(), controls=here.getMapControl(), typeControls=here.getTypeControl(), overviewControls=here.getOverviewControl(), maptype=here.getMapType(), zoom=here.getZoom())" /> 
     11    <span tal:replace="structure python:here.maps_markers(here.getMarkers(), node='map', events=True, color=here.getMarkersColor(), loc=here.geoLocation(), controls=here.getMapControl(), typeControls=here.getTypeControl(), overviewControls=here.getOverviewControl(), maptype=here.getMapType(),)" /> 
    1212  </metal:block> 
    1313</head> 
  • qPloneGoogleMaps/trunk/skins/qPloneGoogleMaps/portlet_maps.pt

    r395 r396  
    55<div metal:define-macro="portlet" 
    66     tal:define="brain python:here.portal_catalog(path='/'.join(here.getPhysicalPath())); 
    7                  longlat python:test(len(brain)==1 and brain[0].geoLocation, brain, [])" 
     7                 longlat python:test(len(brain)==1 and brain[0].portal_type != 'Map' and brain[0].geoLocation, brain, [])" 
    88      tal:condition="longlat"> 
    99 
     
    1212            tal:attributes="src string:http://maps.google.com/maps?file=api&amp;v=2&amp;key=${key}"> 
    1313    </script> 
    14     <span tal:replace="structure python:here.maps_markers(longlat, node='portlet_map', controls='small')" /> 
     14    <span tal:replace="structure python:here.maps_markers(longlat, loc=longlat[0].geoLocation, zoom=5, node='portlet_map', controls='small')" /> 
    1515 
    1616<dl class="portlet" id="portlet-maps">