1

I'm trying to render WMS MapServer data on top of Google Maps using the OpenLayers JS library. My problem arises when I try to render the data as a series of points throughout the New York City area. On my local machine I get a broken image, but on my live server I get no broken PNG data or anything at all.

Any help would be very much appreciated.

You can also check out the live site at: http://134.74.146.40/~Oviedo12/final/subway%20crowding/view.html.

OpenLayers JavaScript code below:

var map;
var mapBounds      = new OpenLayers.Bounds(-8266100.0, 4938263.9, -8204223.4, 4999860.8);
var movementBounds = new OpenLayers.Bounds(-8266100.0, 4938263.9, -8204223.4, 5030000.0);
var aliasproj = new OpenLayers.Projection("EPSG:4326");
var options = {
        projection: "EPSG:4326",
        units: "ft",
        maxResolution: 'auto',
        restrictedExtent: movementBounds,
        maxExtent: mapBounds
    };

function init(){
    map = new OpenLayers.Map('map', options);
    var base_layer = new OpenLayers.Layer.Google(
                    'Google Streets', // the default
                    {   numZoomLevels: 20, 
                        projection: aliasproj, 
                        isBaseLayer: true
                    });

    //change 'Oviedo12' to your login name
    var wms_layer = new OpenLayers.Layer.WMS("WMS Overlay",
        "mapscripts/dynamicwms.php", 
        {layers: 'L_line', transparent: true, format: 'image/png', reqType:'wms'},
        {isBaseLayer: false, visibility: true}
    );
    //*/

    map.addLayers([base_layer, wms_layer])
    //map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
    map.zoomToExtent(map.maxExtent);
    map.addControl(new OpenLayers.Control.MousePosition({position: new OpenLayers.Pixel(0,0)}));
}

Map file code:

MAP
  IMAGETYPE      PNG
  STATUS         ON
  IMAGECOLOR     255 255 255  

  PROJECTION
    "init=epsg:4326"
  END

  SYMBOL
      NAME 'circle'
      TYPE ELLIPSE
      POINTS 1 1 END
      FILLED TRUE
  END

  OUTPUTFORMAT
    NAME png
    DRIVER "GD/PNG"
    MIMETYPE "image/png"
    IMAGEMODE RGB
    EXTENSION "png"
  END

  OUTPUTFORMAT
    NAME jpeg
    DRIVER "GD/JPEG"
    MIMETYPE "image/jpeg"
    IMAGEMODE RGB
    EXTENSION "jpg"
    FORMATOPTION QUALITY=80
  END

END # All map files must come to an end just as all other things must come to...

PHP code for dynamic render:

<?php

if (!extension_loaded("MapScript")) dl("php_mapscript.so");

$request = ms_newowsrequestobj();

foreach ($_GET as $k=>$v) {
     $request->setParameter($k, $v);
}

$request->setParameter("VeRsIoN","1.0.0");
ms_ioinstallstdouttobuffer();
$oMap = ms_newMapobj("../maps/dynamic.map");


$new_layer =ms_newlayerobj($oMap);
$new_layer->set("type", MS_LAYER_POINT);
$new_layer->set("dump", 1);
$new_layer->set("status", 1);
$new_layer->set("name","L_line");
$new_class = ms_newClassObj($new_layer);
$new_style = ms_newStyleObj($new_class);
$new_style-> color->setRGB(0, 0,255);
$new_style->set("symbolname", "circle");
$new_style->set("size", 5);

$new_layer->setConnectionType(MS_POSTGIS);
$new_layer->set("connection","stuff to connect to db");
$data="the_geom from (select the_geom from station2 where lines = 'Canarsie') as foo using unique the_geom using SRID=4326";
echo ;
$new_layer->set("data",$data) ;


$oMap->owsdispatch($request);
$contenttype = ms_iostripstdoutbuffercontenttype();
if ($contenttype == 'image/png')
{
   header('Content-type: image/png');
   ms_iogetStdoutBufferBytes();
}
else
{
    $buffer = ms_iogetstdoutbufferstring();
    echo $buffer;
}
ms_ioresethandlers();
?>
3
  • It looks like MapServer can't open your map file. Warning: [MapServer Error]: msLoadMap(): First token must be MAP, this doesn't look like a mapfile. in /home/Oviedo12/public_html/final/subway crowding/mapscripts/dynamicwms.php on line 13 Warning: Failed to open map file ../maps/dynamic.map in /home/Oviedo12/public_html/final/subway crowding/mapscripts/dynamicwms.php on line 13 Fatal error: Object expected as argument. in /home/Oviedo12/public_html/final/subway crowding/mapscripts/dynamicwms.php on line 16 I would check permissions on that file.
    – DavidF
    Commented Dec 18, 2012 at 21:24
  • I fixed that error and placed the correct mapfile file.
    – user13653
    Commented Dec 18, 2012 at 21:53
  • Your link to the live site doesn't work.
    – Fezter
    Commented Dec 18, 2012 at 22:38

1 Answer 1

1

Check your ms_iostripstdoutbuffercontenttype() function, I think it's setting your $contenttype as text when it should be setting it as PNG. Also, Chrome is complaining that this link is 404'ing:

http://134.74.146.40/~Oviedo12/final/subway%20crowding/js/theme/default/style.css

edit: Also as Dave points out in the comment, set your map to a static path instead of a dynamic one and see if that helps.

edit x2: Change your $oMap in your php code from this:

ms_newMapobj("../maps/dynamic.map");

to this:

ms_newMapobj("http://134.74.146.40/~Oviedo12/final/subway%20crowding/maps/dynamic.map");

10
  • I finished fixing that error, I'm still getting a Warning: [MapServer Error]: error.Warning: [MapServer Error]: msLoadMap(): (/home/Oviedo12/public_html/final/subway crowding/maps/maps/dynamic.map) in /home/Oviedo12/public_html/final/subway crowding/mapscripts/dynamicwms.php on line 13
    – user13653
    Commented Dec 18, 2012 at 21:28
  • Yeah, that's a bad link to your dynamic.map file, you've got one too many 'maps' in the path.
    – Mintx
    Commented Dec 18, 2012 at 21:32
  • I saw that error a while ago, but to my knowledge I have no idea what it mean. I don't use any file of that name. I think it has something to so with twitter bootstrap, as that's what I'm using for my frontend.
    – user13653
    Commented Dec 18, 2012 at 21:33
  • See edit x2 in my answer above.
    – Mintx
    Commented Dec 18, 2012 at 21:36
  • After the x2 edit I still get the same error: Warning: [MapServer Error]: msLoadMap(): (134.74.146.40/~Oviedo12/final/subway%20crowding/maps/…) in /home/Oviedo12/public_html/final/subway crowding/mapscripts/dynamicwms.php on line 13................Also, if i change it back to ms_newMapobj("../maps/dynamic.map"); is "kinda works".
    – user13653
    Commented Dec 18, 2012 at 21:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.