[mapserver-dev] support for label priority in php mapscript

Steve Lime Steve.Lime at dnr.state.mn.us
Tue Sep 30 08:34:53 EDT 2008


Cool, this is probably something we can get into 5.2.1, at least the numerical
part. Swig:MapScript uses a setBinding/removeBinding approach that should be
used here, if not already implemented. Syntax becomes:

  # in Perl
  $label->setBinding(mapscript::MS_LABEL_BINDING_PRIORITY, $myColumnName);

I'll defer to one of the PHP/MapScript devs...

Steve

>>> "Guy Carpenter" <guyc at atgis.com.au> 09/30/08 1:21 AM >>>
I'm using mapserver 5.2.0 and the PHP mapscript bindings.
I would like to be able to use the label priority features
introduced in mapserver 5.0, as documented here:
	https://trac.osgeo.org/mapserver/ticket/1619

I see that the php bindings do not include access
to the new labelObj->priority attribute, so
Below are the changes required to support 
label priority via the php interface...

Changes to support the numeric priority values are just two lines...
 
--- mapserver-5.2.0-orig/mapscript/php3/php_mapscript.c      2008-06-26
05:07:30.000000000 +1000
+++ mapserver-5.2.0/mapscript/php3/php_mapscript.c  2008-09-30
09:39:39.000000000 +1000
@@ -8584,6 +8584,7 @@ static long _phpms_build_label_object(la
     add_property_long(return_value,   "mindistance",plabel->mindistance);
     add_property_long(return_value,   "partials",   plabel->partials);
     add_property_long(return_value,   "force",      plabel->force);
+    add_property_long(return_value ,  "priority",   plabel->priority);
 
     MAKE_STD_ZVAL(new_obj_ptr);  /* Alloc and Init a ZVAL for new object */
     _phpms_build_color_object(&(plabel->color),list, new_obj_ptr
TSRMLS_CC);
@@ -8670,6 +8671,7 @@ DLEXPORT void php3_ms_label_setProperty(
     else IF_SET_LONG(  "mindistance",  self->mindistance)
     else IF_SET_LONG(  "partials",     self->partials)
     else IF_SET_LONG(  "force",        self->force)
+    else IF_SET_LONG(  "priority",     self->priority)
     else
     {
         php3_error(E_ERROR,"Property '%s' does not exist in this object.", 


There is also the PRIORITY "[attribute]" form of this
command which is more complicated to implement.
Below is a working solution, but I did not find similar code in the
php bindings to take a lead from, so please cast a critical
eye over it for style and convention mistakes.

This patch is *instead of* the above one, and adds support for
both number label priority and binding priority to a table attribute.


/usr/local/src/mapserver/mapserver-5.2.0/mapscript/php3/php_mapscript.c
---
/usr/local/src/mapserver/mapserver-5.2.0-orig/mapscript/php3/php_mapscript.c
2008-06-26 05:07:30.000000000 +1000
+++ /usr/local/src/mapserver/mapserver-5.2.0/mapscript/php3/php_mapscript.c
2008-09-30 15:58:25.000000000 +1000
@@ -8584,6 +8584,7 @@ static long _phpms_build_label_object(la
     add_property_long(return_value,   "mindistance",plabel->mindistance);
     add_property_long(return_value,   "partials",   plabel->partials);
     add_property_long(return_value,   "force",      plabel->force);
+    add_property_long(return_value ,  "priority",   plabel->priority);
 
     MAKE_STD_ZVAL(new_obj_ptr);  /* Alloc and Init a ZVAL for new object */
     _phpms_build_color_object(&(plabel->color),list, new_obj_ptr
TSRMLS_CC);
@@ -8612,6 +8613,33 @@ static long _phpms_build_label_object(la
 
 
 /**********************************************************************
+ *                        set_label_priority
+ **********************************************************************/
+static void set_label_priority(pval *pThis, labelObj *self, pval
*pNewValue)
+{
+  // if string is not null and starts with '[' it is an attribute
+  if (pNewValue->value.str.val && pNewValue->value.str.val[0]=='[') 
+  {
+    // strip leading '[' and trailing ']' from field and duplicate field
+    char *field = pNewValue->value.str.val;
+    char *endField = index(field,']');
+    int len = endField==NULL ? strlen(field) : endField-field-1;  //
forgive missing ']'
+    char *copy = malloc(len+1);
+    memcpy(copy, field+1, len);
+    copy[len]='\0';
+    self->bindings[MS_LABEL_BINDING_PRIORITY].item = copy;
+    self->numbindings++;
+    _phpms_set_property_string(pThis, "priority", field, E_ERROR
TSRMLS_CC);
+  }
+  else
+  {
+    convert_to_long(pNewValue);
+    _phpms_set_property_long(pThis, "priority", pNewValue->value.lval,
E_ERROR TSRMLS_CC); 
+    self->priority = pNewValue->value.lval;
+  }
+}
+
+/**********************************************************************
  *                        label->set()
  **********************************************************************/
 
@@ -8670,6 +8698,11 @@ DLEXPORT void php3_ms_label_setProperty(
     else IF_SET_LONG(  "mindistance",  self->mindistance)
     else IF_SET_LONG(  "partials",     self->partials)
     else IF_SET_LONG(  "force",        self->force)
+    else if (strcmp(pPropertyName->value.str.val, "priority") == 0) 
+    {      
+      set_label_priority(pThis, self, pNewValue);
+    }
     else
     {
         php3_error(E_ERROR,"Property '%s' does not exist in this object.", 







Thanks
Guy Carpenter
Atherton Tablelands GIS








_______________________________________________
mapserver-dev mailing list
mapserver-dev at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapserver-dev



More information about the mapserver-dev mailing list