Help - view.w - multi display of maps

hi have 'Contact' content type with map, his DefaultView template display correctly the map:

<td class="contactMap">
	<div tal:content="structure python: view.w['IGeolocatable.geolocation'].render()">
</td>

important thing to display map is:
view.w
= the DefaultView of one 'Contact' instance itself.

Now i have Department with list of 'Contact'

    offices = RelationList(
        title=_(u'offices', default=u'offices'),
        default=[],
        missing_value=[],
        value_type=RelationChoice(
            title=u'offices',
            source=CatalogSource(portal_type=['Contact',]),
        ),
        required=False,
    )

I have problem displaying the list of 'Contact' in DefaultView of Department.
I tried to get view of every Contact in Department
contact = aq_inner(contact)
oc_view = api.content.get_view('officecontact-view', contact, self.request)

but oc_view.w is None, so I can not use oc_view in template of Department

Many thanks for help.

What we do is:

    <section id="contacts-map">
      <div id="contact-map" class="pat-leaflet"
        data-pat-leaflet='{
          "fullscreencontrol": true,
          "locatecontrol": true,
          "zoomcontrol": true,
          "autolocate": false,
          "minimap": false,
          "geosearch": false,
          "addmarker": false,
          "map_layers": [{"title": "Map", "id": "OpenStreetMap.Mapnik"},{"title": "Satellite", "id": "Esri.WorldImagery"}]
        }'
        data-geojson='{}'
        tal:attributes="data-geojson view/getgeojson">
      </div>
    </section>

and in the view:

   # getcontacts return the list of contacts as brains

    def getgeojson(self):        
        contacts = self.getcontacts()
        jd = { 
               "type": "FeatureCollection",
               "features": []
             }
        for b in contacts:
            bt = self.create_feature(
                                       # here various data extracted from brain b, with latitude and longitude
                                     )
            jd['features'].append(bt)
        return json.dumps(jd)

where create_feature returns:

        bt = {
                "type": "Feature",
                "id": contactid,
                "properties": {
                  "popup": popupContent, <- here you can have the popup html
                  "color": "a color",
                  "editable": False
                },
                "geometry": {
                  "type": "Point",
                  "coordinates": [
                      lg,
                      lt
                    ]
                }
              }

Hope can be useful to you.

1 Like

dude @yurj your beautiful code works great!
even in macro :slight_smile:

Many thanks for your help!!!

1 Like

Must thanks @petschki , @laulaz and the other amazing developers for this precious product.

I think there are alternative implementations that don't use geojson.

Note: you can use @memoize decorator over the call above with the sum of brains modification time to speed up page loading.

2 Likes