0

What I'm trying to accomplish: take the functionality below (see picture) and do the same without using a MapServer template (if this is even possible).

I currently have a mapfile, and an openlayers file. All the data is being displayed correctly.

In my mapfile, I reference a database. I call out that database by a column name so what is what's used for the label on the map. Quite simple.

Now, the thing here is that I'm accessing just a standard php/html file. Not a mapserver template, like:

http://192.168.2.164/cgi-bin/mapserv.exemap=%2Ftmp%2Fnavhome%2Fnavcore%2Ftemplates3%2FAllAirports.map&mode=nquery&imgext=-180.000000+-107.943706+180.000000+107.943706&imgxy=640+384&zoom=0&qlayer=Cities&layers=world&searchmap=true&img.x=705&img.y=347

Example: 123.456.7.890/mymap.php in the browser is what I want. Not the above.

Now if I wanted to accomplish this using a MapServer template (correct me if I'm wrong on my terminology), this has proven to be quite easy, because you can reference

map_body.html
map_header.html
map_footer.html

in your Mapfile. In those files you can do some javascript and whatnot, reference the columns in the DB and it works. See below for an example of this (top left is the onClick functionality when you click on a point on the map, where the mouse is is just the mouseover).

See below: this is what I want to do without the cumbersome MapServer functionality, ie sluggish navigation buttons this is what I want to do JUST using a MapFile and OpenLayers, no MapServer template

So what I'm trying to wrap my head around is: how do you set up the database references in your .html/php file? Or, how do you reference the templates (map_body.html, map_header.html, map_footer.html) from your MapFile in your OpenLayers file?

1 Answer 1

1

I am not sure what you are trying to achieve here (the image is not extra clear), but for whatever you are trying to do, you can certainly achieve it without using MapServer template.

If the issue is about clicking on an OpenLayers map and have some information back from a database, there are many ways for achieving this. Few simple approaches can be:

  1. Serve the data as a simple WMS layer and use a GetFeatureInfo request. For OpenLayers see docs and example. For mapserver see docs. Even better, have a look at what something like MapProxy can offer. With this solution you can completely bypass MapServer templates and php.

  2. Serve the data as simple tile images. For OpenLayers have a look at XYZ and TMS layers, for example. And for generating the tiles, again, have a look into MapProxy. Once this is set-up, you can then fire a simple Ajax request to the server on a click event, passing the x-y coordinates. Have a look at this example for the click event. Whatever you do on the server for constructing your response is up to you.

  3. Serve the data as a geoJSON and create a vector layer. See a vector example here. This is a completely different scenario, your data is now in the browser, what you do with it in JavaScript and with the OpenLayers API is up to you.

There are other solutions and this is just a very simple overview. Hope it gives you some input to start with though. :)

5
  • Hi Decio, thank you for the very detailed reply. And yeah the image came out terribly in my queston, just right click it, 'copy image url' and put it in a new browser tab. I think I'll try your #1 suggestion. Will post back here soon and let you know how it goes :)
    – Nubtacular
    Jun 22, 2013 at 19:49
  • Decio, mind taking a look at this? It's a mess but I'm not sure where to go from here. I didn't add anything new to the mapfile, just the php file. The main js console error I'm getting is: Resource interpreted as Image but transferred with MIME type text/html . See here: gist.github.com/DavidPardy/5881065 Also note: var layer1 is what I was using before trying to implement getfeatureinfo (and working correctly). var CustomerAirports is what I have been toying with.
    – Nubtacular
    Jun 27, 2013 at 22:46
  • I will have a look, but not today. If you are working on a WMS layer it seems you are getting mixed up your getMap and getFeatureInfo calls.
    – Decio
    Jun 28, 2013 at 8:31
  • 1
    Your mapfile configuration is wrong. If you follow the links I gave you and read the docs you would notice. From the mapserver docs there is a clear example on how to setup a wms service. Then if you want to implement this in OpenLayers have a read at OpenLayers.Layer.WMS and especially at OpenLayers.Control.WMSGetFeatureInfo. If you go through this stuff, you can not be lost, it is all clearly explayned.
    – Decio
    Jun 28, 2013 at 22:02
  • Alright, making progress, but still getting _ request failed with curl error code 7 (couldn't connect to host)_ in the log. I created a separate mapfile (just for customerairports.db, which is being referenced like so. Now, if I go to http://192.168.2.164/cgi-bin/mapserv.exe?map=/data2/html/OL_AllWorldAirports/catest.map' directly, it gives me a blank page but if you inspect element, it's recognizing the html (albeit blank) from map_body.html. Log. I tried it in a separate php file and the data is appearing. Thoughts?
    – Nubtacular
    Jul 1, 2013 at 23:32

Your Answer

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

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