It seems like I am having difficulties in normalizing raw map files' resolutions to OpenLayer's use most probably in parameters mapext and imgext. I hope you can help me with this.

Using raw (.shp, .shx, .xml, .prj, .dbf) and associated raster files for landuse-related data included in an ArcGIS 10 project (.mxd) that I've obtained from a credible private source, I have used Mxd2Qgs to read .mxd project to .qgs. Then I used Quantum GIS' MapServer Export plugin to export selected layers to a MAP file.

I can view the generated map in browser but cannot do so when I use it through OpenLayers. The generated map file has an extent:

EXTENT 272813.696194 1546212.773835 340292.781152 1587773.606956 
# (it's quite huge).

I have tried adding to OpenLayer's map initialization properties maxResolution, numZoomLevels, units, projection and displayProjection but there is no map rendered, although the map has been queried. I have just guessed the maxResolution here, copying from other huge datasets online :)

The map has never been queried when I added the map file's EXTENT to maxExtent: OpenLayers.Bounds(...). The same thing goes when I used the files included in the MS4W tutorial #1 data set.

My questions would be:

  • How to know a given map's maxResolution parameter for OpenLayers? Can this be guessed?
  • Are there any special processing needed for map/shapefiles before they can be used in OpenLayers?
  • How should a map file be written so that it could be used in OpenLayers?

EDIT: Attached MAP file and JavaScript files.


You can use maxResolution: 'auto', if you dont know your maxresolution. it is how many "units" does a pixel on the screen represent.

if you want to calculate it you can use this formule: (details are here)

Units Conversion Factor
inches        1
ft           12

mi        63360
m       39,3701
km      39370,1
dd      4374754      Decimal Degrees

Map DIV               The size of the area on the webpage the map will go in.
WIDTH         600     pixel
HEIGHT        600     pixel

Units        dd      Units our map is in for OpenLayers            
Factor  4374754      Scale factor based on units.

dx         = Left - Right
Scale      = dx/WIDTH * dpi * Factor


Resolution = Scale / ( dpi * factor ) = 4000000 / ( 72 * 4374754  ) = 0.012699

with your que. about shapefile, you can use directly shapefile in openlayers with Openlayers shapefile method.


but i suggest that you should use geojson format from server or local for getting faster performans and more browser compatibility which i have been using it for a long time. You can easily convert your data to geojson with qgis. Besides this, javascript shapefile viewer is another choose. Some example pls see here and Convert Shapfiles and DBF to GeoJSON using JavaScript here.

i hope it helps you...

  • Thank you for your hints about the conversions Aragon these are very helpful. I'm using MAP FILES now but with your suggestion I will try them out as GeoJSON for faster performance. Finally I got the MAP FILE to render nicely in openlayers. – raiser00 Apr 29 '12 at 14:51
  • Sorry for the delayed comment this should have been included on the previous. I've accidentally pressed Enter. The error in my first attempt was my MAP FILE's contents and openlayers' map initialization wasn't in sync and I was using the wrong projection :D initialization should have been link Thanks a lot again. Now I can move on with my newbie adventure in mapserver and openlayers :) – raiser00 Apr 29 '12 at 15:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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