Ruby/MapScript quark in version 5.0.0

Brant Anderson rabrant at GMAIL.COM
Sun Nov 18 01:16:46 PST 2007


Heres some code I wrote in Ruby on Rails for a dynamic map:
  def dynamic_map
    # ====================
    # Grab values from the form
    # ====================
    @minx_d = params[:minx_d].to_f # default extent values
    @miny_d = params[:miny_d].to_f
    @maxx_d = params[:maxx_d].to_f
    @maxy_d = params[:maxy_d].to_f
    @minx_img = params[:minx_img].to_f # image coordinate values
    @miny_img = params[:miny_img].to_f
    @maxx_img = params[:maxx_img].to_f
    @maxy_img = params[:maxy_img].to_f
    @pin = params[:pin].to_s # parcel identification number
    @minx = params[:minx].to_f # current extent values
    @miny = params[:miny].to_f
    @maxx = params[:maxx].to_f
    @maxy = params[:maxy].to_f
    @zoomfactor = params[:zoomfactor].to_i # -2 is zoomout, -1 or 1 is
recenter, 2 is zoomin (Integer value).
    @tool = params[:tool].to_s # This should match the 'getToolbox()'
JavaScript function.

    # ==============
    # Initialize MapObj
    # ==============
    @map = MapObj.new session['mapfile']
    @map.setExtent @minx, @miny, @maxx, @maxy

    # ====================
    # Paint the selection yellow.
    # ====================
    layer = @map.getLayerByName 'parcel_poly'
    layer.classitem = 'PIN'

    class_poly_hilite = layer.getClass 0
    layer.insertClass class_poly_hilite

    class_poly_hilite.name = 'poly_hilite'
    class_poly_hilite.setExpression @pin.strip

    class_poly_hilite_style = class_poly_hilite.getStyle 0
    class_poly_hilite_style.color.setRGB 250, 250, 125

    # =============
    # Add a push-pin.
    # =============
    layer_pt = @map.getLayerByName 'parcel_point'
    layer_pt.classitem = 'pin'

    class_pt_hilite = layer_pt.getClass 0
    layer_pt.insertClass class_pt_hilite

    class_pt_hilite.name = 'pt_hilite'
    class_pt_hilite.setExpression @pin.strip

    class_pt_hilite_style = class_pt_hilite.getStyle 0
    class_pt_hilite_style.size = 32
    class_pt_hilite_style.setSymbolByName @map, 'pushpin'

    # ===================================
    # Apply the zoom (aka change the extent value).
    # ===================================
    if @minx_img != @maxx_img && @miny_img != @maxy_img
      apply_box @map, @minx_img, @miny_img, @maxx_img, @maxy_img
    elsif @tool == 'fullview'
      @map.setExtent @minx_d, @miny_d, @maxx_d, @maxy_d
    else
      apply_zoom @map, @zoomfactor, @minx_img, @miny_img
    end

    # Set the new extent values to be sent back to the form.
    @minx = @map.extent.minx.to_f
    @miny = @map.extent.miny.to_f
    @maxx = @map.extent.maxx.to_f
    @maxy = @map.extent.maxy.to_f

    render :partial => 'map_image'
  end

Here's a snippet from my mapfile:
  LAYER #-- Parcels Polygon Layer
    NAME parcel_poly
    DATA parcelpydoug04
    MAXSCALE 72000
    STATUS DEFAULT
    TYPE POLYGON
    TRANSPARENCY 50
    CLASS
      NAME "Parcels"
      COLOR -1 -1 -1
      OVERLAYOUTLINECOLOR 250 0 0
      OVERLAYSYMBOL 'circle'
      OVERLAYSIZE 2
    END
  END #-- Parcels Polygon Layer

  LAYER #-- Parcels Point Layer
    NAME parcel_point

    CONNECTIONTYPE postgis
    CONNECTION "user=<username_goes_here> dbname=experiments host=localhost
port=5432 password=<password_goes_here>"
    DATA "wkb_geometry from mn_douglas_parcelpoints"

    MAXSCALE 72000
    STATUS DEFAULT
    TYPE POINT
    #-- TOLERANCEUNITS miles
    #-- TOLERANCE 10
    TRANSPARENCY 50
    CLASS
      NAME "Parcel Point"
      COLOR 0 250 0
      SYMBOL 'circle'
      SIZE 10
    END
  END #-- Parcels Point Layer

In version 4, the parcel lines and points are drawn. The code written above
highlights the selected parcel and changes the point graphic to a push-pin.
In version 5, the parcel lines and points are not drawn. Only the
highlighted parcel is drawn. Why? How do I write my code so that it displays
the defaults from the mapfile as well as the newly defined class? I'm
stumped.

Any comments or suggestions appreciated.
~Brant
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20071118/304b6fd3/attachment.htm>


More information about the MapServer-users mailing list