Upon further review, I was not setting the srs() of the layer. However, doing
this did not solve the problem.

After digging a while, the problem only seems to occur whenever the dynamic
layer is empty. When I first add the layer, and it contains no points, the
zoom_all function does not appear to work correctly. However, once a point
is added to the dynamic layer, zoom_all() works fine.

Here is the code I am using to create the layer:

      feature_type_style lstyle;
      point_datasource *ps = new point_datasource();
      datasource_ptr ds(ps);

      // create the point rule
      rule_type point_rule;

     // add image using point_rule.append()

    ...

      // add the rule to the feature style
      lstyle.add_rule(point_rule);
      // insert style to the map
      map->insert_style(styleName, lstyle);

      // create the layer
      Layer lyr(layerName);
      lyr.set_datasource(ds);
      lyr.add_style(styleName);
      lyr.set_srs("+proj=latlong +datum=WGS84");
      map->addLayer(lyr);


Dane Springmeyer-4 wrote:
> 
> 
> On Oct 18, 2010, at 8:37 AM, mjb1999 wrote:
> 
>> 
>> I am writing a small Mapnik viewer application using c++, much like the
>> viewer demo application.
> 
> Curious, is there a reason you are not using/extending the viewer? Are you
> using a different GUI framework than QT?
> 
>> I load a map from an XML file and I display it on
>> screen. 
>> 
>> In this application, I give the user the option to view the entire map in
>> the window. I use the zoom_all() function to accomplish this, and it
>> works
>> fine. However, I also add a point_datasource() layer that dynamically
>> shows
>> a GPS position. When I do this, the zoom_all() function no longer works
>> as
>> expected. The map area is much larger than I would expect.
>> 
> 
> Okay, interesting. Are the point datasource geometries in the same
> coordinate system as your map? Are you remembering to set the proper srs
> for the layer you are adding the point datasource to?
> 
>> I am thinking that my problem is that I do not specify the extent of the
>> dynamic layer when I create it, but I am not sure how to do this.
> 
> Point Datasource inherits from the Memory Datasource (which you could use
> directly). But, either way the extent *should* be calculated for you
> automatically when the datasource.envelope() is called for the layer. For
> the memory datasource that happens here:
> 
> http://trac.mapnik.org/browser/trunk/src/memory_datasource.cpp#L31
> 
> The code looks fine to me on first glance, but you may be seeing a bug.
> Please let me know what you find and if you can narrow it to a small
> testcase.
> 
> Dane
> 
> _______________________________________________
> Mapnik-users mailing list
> [email protected]
> https://lists.berlios.de/mailman/listinfo/mapnik-users
> 
> 

-- 
View this message in context: 
http://old.nabble.com/Mapnik-zoom_all-c%2B%2B-API-with-dynamic-layers-tp29990901p30004379.html
Sent from the Mapnik - Users mailing list archive at Nabble.com.

_______________________________________________
Mapnik-users mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/mapnik-users

Reply via email to