def map_marker(self):
        collection = self._getcollection()
        brains = collection.queryCatalog()
        vocab = getUtility(IVocabularyFactory, name='wcc.vocabulary.country')

        if not brains:
            return None

        map_data = list()
        for i in brains:
            obj = i.getObject()
            country = vocab.name_from_code(obj.country_code)
            capital = lookup_capital(obj.country_code)
            location = self.query_geolocation(country, capital)[1]
            lat = location[0]
            lng = location[1]

            # Empty bodytext will return none
            if obj.bodytext:
                text = obj.bodytext.output
            else:
                text = ''

            map_data.append(
                {'title': obj.title,
                 'body': text,
                 'lat': lat,
                 'lng': lng}
                )
        return json.dumps(map_data)
 def static_map(self):
     source = 'https://www.mapquestapi.com/staticmap/v4/getmap?key='
     collection = self._getcollection()
     brains = collection.queryCatalog()
     vocab = getUtility(IVocabularyFactory, name='wcc.vocabulary.country')
     api_key = ''
     settings  = getSettings()
     if settings.openmapquest_api_key:
         api_key = settings.openmapquest_api_key
     
     source += api_key+'&size=900,500&type=map&imagetype=png&pois='
     if not brains:
         return None
     map_data = list()
     for brain in brains:
         obj = brain.getObject()
         country = vocab.name_from_code(obj.country_code)
         capital = lookup_capital(obj.country_code)
         
         if country == "C\xc3\xb4te d'Ivoire":
             query = "&country=Cote d'Ivoire"
         elif country in ['Netherlands Antilles']:
             query = "&location="+capital
         else:
             query ='&country='+country
         
         loc = requests.get('http://www.mapquestapi.com/geocoding/v1/address?key='+api_key+query)
         if not loc:
             return ''
         
         location = loc.json()
 
         #place, (lat, lng) = location
         if location['info']['statuscode'] == 0:
             lat = location['results'][0]['locations'][0]['latLng']['lat']
             lng = location['results'][0]['locations'][0]['latLng']['lng']
         else:
             lat = 0
             lng = 0
         
         map_data.append(
             {'title':obj.title,
              'lat': lat,
              'lng': lng})
     
     if len(map_data):
         for mapd in map_data:
             indx = map_data.index(mapd)
             
             source += str(indx+1)+','+str(mapd['lat'])+','+str(mapd['lng'])
             if indx == 0:
                 source += ',0,0'
             if (indx+1) != len(map_data):
                 source += '|'
     
 
     return source
Example #3
0
    def map_state(self):
        vocab = getUtility(IVocabularyFactory, name='wcc.vocabulary.country')
        country = vocab.name_from_code(self.context.country_code)
        capital = lookup_capital(self.context.country_code)
        api_key = ''
        settings  = getSettings()
        capital = unicode(capital, errors='ignore')
        if settings.openmapquest_api_key:
            api_key = settings.openmapquest_api_key
        #location = self._query_geolocation(country, capital)
        if country == "C\xc3\xb4te d'Ivoire":
            query = "&country=Cote d'Ivoire"
        elif country in ['Netherlands Antilles',]:
            query = "&location="+capital
        else:
            query ='&country='+country
        loc = requests.get('http://open.mapquestapi.com/geocoding/v1/address?key='+api_key+query)
        
        if not loc:
            loc = requests.get('http://open.mapquestapi.com/geocoding/v1/address?key='+api_key+'&capital='+capital)
        
        
        
        #additional condition to fix problem with congo
        if not loc:
            return ''
        
        location = loc.json()

        #place, (lat, lng) = location
        if location['info']['statuscode'] == 0:
            lat = location['results'][0]['locations'][0]['latLng']['lat']
            lng = location['results'][0]['locations'][0]['latLng']['lng']
        else:
            lat = 0
            lng = 0
        return '''
        cgmap.state['country-cgmap'] = {
            lon : %(lon)s,
            lat : %(lat)s,
            zoom : 4
        }
        ''' % {'lon': lng, 'lat': lat}
Example #4
0
    def table_widgets(self):
        result = []
        provider = self.provider

        for i in ['population', 'surface_area']:
            widget = self.w[i]
            result.append({
                'label': widget.label,
                'render': widget.render()
            })
        result.append({
            'label': _(u'Capital'),
            'render': lookup_capital(self.context.country_code)
        })
        for i in ['gni_percapita',
                  'classification',
                  'languages']:
            widget = self.w[i]
            result.append({
                'label': widget.label,
                'render': widget.render(),
            })

        # religion
        religions = getattr(self.context, 'religions', [])
        rows = ['<tr><th>%s :</th><td>%s%%</td></tr>' % (i['religion'],
            i['percentage']) for i in religions]
        result.append({
            'label': _(u'Religions'),
            'render': 
            '<table id="country-religions-table">%s</table>' % ''.join(rows)
        })

        denominations = getattr(self.context, 'christianity_denominations', [])
        rows = ['<tr><th>%s :</th><td>%s</td></tr>' % (i['denomination'],
            i['count']) for i in denominations]
        result.append({
            'label': _(u'Denominations'),
            'render': 
            '<table id="country-denominations-table">%s</table>' % ''.join(rows)
        })
        return result
 def geocode_map(self):
     collection = self._getcollection()
     if not collection:
         return []
     brains = collection.queryCatalog()
     vocab = getUtility(IVocabularyFactory, name='wcc.vocabulary.country')
     countries = []
     if not brains:
         return countries
     for brain in brains:
         obj = brain.getObject()
         country = vocab.name_from_code(obj.country_code)
         capital = lookup_capital(obj.country_code)
         if country == "C\xc3\xb4te d'Ivoire":
             countries.append("Cote d'Ivoire")
         elif country in ['Netherlands Antilles']:
             countries.append(capital)
         else:
             countries.append(country)
     return countries
 def orig_country_names(self):
     collection = self._getcollection()
     if not collection or None:
         return {}
     brains = collection.queryCatalog()
     vocab = getUtility(IVocabularyFactory, name='wcc.vocabulary.country')
     countries = {}
     if not brains:
         return countries
     for brain in brains:
         obj = brain.getObject()
         country = vocab.name_from_code(obj.country_code)
         capital = lookup_capital(obj.country_code)
         if country not in countries.keys():
             if country == "C\xc3\xb4te d'Ivoire":
                 countries["Cote d'Ivoire"] = "Cote d'Ivoire"
             elif country in ['Netherlands Antilles']:
                 countries[country] = 'Willemstad'
             else:
                 countries[country] = country
     return countries
    def map_marker(self, hidden=None):
        collection = self._getcollection()
        if not collection or None:
            return {}
        brains = collection.queryCatalog()
        vocab = getUtility(IVocabularyFactory, name='wcc.vocabulary.country')
        api_key = ''
        settings  = getSettings()
        if settings.openmapquest_api_key:
            api_key = settings.openmapquest_api_key

        if not brains:
            return None

        map_data = list()
        for i in brains:
            obj = i.getObject()
            country = vocab.name_from_code(obj.country_code)
            capital = lookup_capital(obj.country_code)
            
            if country == "C\xc3\xb4te d'Ivoire":
                query = "&country=Cote d'Ivoire"
            elif country in ['Netherlands Antilles']:
                query = "&location="+capital
            else:
                query ='&country='+country
                
            loc = requests.get('http://www.mapquestapi.com/geocoding/v1/address?key='+api_key+query)
            #if not loc:
            #    loc = requests.get('http:www//open.mapquestapi.com/geocoding/v1/address?key='+api_key+'&capital='+capital)
            
            
            
            #additional condition to fix problem with congo
            if not loc:
                return ''
            
            location = loc.json()
    
            #place, (lat, lng) = location
            if location['info']['statuscode'] == 0:
                lat = location['results'][0]['locations'][0]['latLng']['lat']
                lng = location['results'][0]['locations'][0]['latLng']['lng']
            else:
                lat = 0
                lng = 0
            
            #location = self.query_geolocation(country, capital)[1]
            #lat = location[0]
            #lng = location[1]

            # Empty bodytext will return none
            if obj.bodytext:
                text = obj.bodytext.output
            else:
                text = ''

            map_data.append(
                {'title': obj.title,
                 'body': text,
                 'lat': lat,
                 'lng': lng}
                )
        if hidden:
            return map_data
        return json.dumps(map_data)