[1] | 1 | from zope.interface import implements |
---|
| 2 | from geo.interfaces import IPoint |
---|
| 3 | from zope.app.annotation.interfaces import IAnnotations, IAnnotatable |
---|
| 4 | from Products.CMFPlone.CatalogTool import registerIndexableAttribute |
---|
| 5 | from persistent.mapping import PersistentMapping |
---|
| 6 | |
---|
| 7 | GEOLOCATION_KEY = "geolocation.adapters.geolocation" |
---|
| 8 | class Point(object): |
---|
| 9 | implements(IPoint) |
---|
| 10 | |
---|
| 11 | def __init__(self, context): |
---|
| 12 | """ init """ |
---|
| 13 | self.annotations = IAnnotations(context) |
---|
| 14 | self.point = self.annotations.get(GEOLOCATION_KEY, None) |
---|
| 15 | if self.point == None: |
---|
| 16 | self.annotations[GEOLOCATION_KEY] = PersistentMapping() |
---|
| 17 | self.point = self.annotations[GEOLOCATION_KEY] |
---|
| 18 | self.point['targetId'] = '' |
---|
| 19 | self.point['extrude'] = 0 |
---|
| 20 | self.point['tessellate'] = 0 |
---|
| 21 | self.point['altitudeMode'] = 'clampToGround' |
---|
| 22 | self.point['coordinates'] = (0,0,0) |
---|
| 23 | |
---|
| 24 | def getCoordinates(self): |
---|
| 25 | return self.point['coordinates'] |
---|
| 26 | |
---|
| 27 | def setCoordinates(self, coordinates): |
---|
| 28 | self.point['coordinates'] = coordinates |
---|
| 29 | |
---|
| 30 | def getAltitudeMode(self): |
---|
| 31 | return self.point['altitudeMode'] |
---|
| 32 | |
---|
| 33 | def setAltitudeMode(self, altitudeMode): |
---|
| 34 | self.point['altitudeMode'] = altitudeMode |
---|
| 35 | |
---|
| 36 | def getTessellate(self): |
---|
| 37 | return self.point['tessellate'] |
---|
| 38 | |
---|
| 39 | def setTessellate(self, tessellate): |
---|
| 40 | self.point['tessellate'] = tessellate |
---|
| 41 | |
---|
| 42 | def getExtrude(self): |
---|
| 43 | return self.point['extrude'] |
---|
| 44 | |
---|
| 45 | def setExtrude(self, extrude): |
---|
| 46 | self.point['extrude'] = extrude |
---|
| 47 | |
---|
| 48 | def getTargetId(self): |
---|
| 49 | return self.point['targetId'] |
---|
| 50 | |
---|
| 51 | def setTargetId(self, targetId): |
---|
| 52 | self.point['targetId'] = targetId |
---|
| 53 | |
---|
| 54 | coordinates = property(getCoordinates, setCoordinates, """ see interface """) |
---|
| 55 | altitudeMode = property(getAltitudeMode, setAltitudeMode, """ see interface """) |
---|
| 56 | tessellate = property(getTessellate, setTessellate, """ see interface """) |
---|
| 57 | extrude = property(getExtrude, setExtrude, """ see interface """) |
---|
| 58 | targetId = property(getTargetId, setTargetId, """ see interface """) |
---|
| 59 | |
---|
| 60 | default = None |
---|
| 61 | def geoLocation(obj, portal, **kw): |
---|
| 62 | """ return the location list """ |
---|
| 63 | if hasattr(obj.aq_base, 'geoLocation'): |
---|
| 64 | return obj.geoLocation() |
---|
| 65 | adapter = IPoint(obj, None) |
---|
| 66 | if adapter: |
---|
| 67 | coord = adapter.coordinates[0:2] |
---|
| 68 | if not coord: |
---|
| 69 | return None |
---|
| 70 | else: |
---|
| 71 | return coord |
---|
| 72 | return default |
---|
| 73 | |
---|
| 74 | registerIndexableAttribute('geoLocation', geoLocation) |
---|