Hapinoy:Modification of Demo Application
Modification of MapServer Demo Application
First step is to locate “mapserv-demo” folder on your computer. You will open “C” drive and point to “ms4w” folder. Open that folder and point to folder named “apps”. Open “apps” folder to view content and then point to folder named “mapserv-demo”. Open folder “mapserv-demo” and you will see many folders and files.
The” mapserv-demo” contains files to run demo application. To test this application, as well your mapserver, you will enter following URL in your browser (Mozilla Firefox, IE):
If the installation of mapserver went well, you should see this screen:
So Congratulation, you are running mapserver!
- If you have not seen this screen**
You should check your computer security settings and allow mapserver to run it!
Make sure your Apache port ”80” is open and available!
Or go on line for more help. The Link is: http://mapserver.org/documentation.html
Modification of “mapserv-demo”
Follow this path to open demo application (C:\ms4w\apps\mapserv-demo). After you are there select any folder and press Ctrl + A to select all files and folders. After that press Ctrl + C to copy all folders and files, then minimize this Window and create new folder named “Original mapservdemo”. Open newly created folder and click anywhere in white space and press Ctrl + V to paste original files and folders . This way we can ensure we have original files in case you need them.
The Next step is to go back to C:\ms4w\apps\mapserv-demo and we are going to select and open “data” folder. We are going to delete everything in there and copy our data. For this folder we need to have files that have extensions like this (.shx, .shp, .dbf, and .xml).
So what you need to do is to locate your map files with these extensions and copy them in “data” folder. This files are necessary for mapserver in order to draw maps!
The next is to modify file called “Itasca.map”, you can use any text editor. We have used Visual Studio, but you can use anything you want for text editor.
The file looks like this and everything in red we have changed to match our “data” files.
# # Start of map file # MAP NAME itasca STATUS ON SIZE 400 600 EXTENT 112.570669084057 5.3232969446934 131.138752856584 18.5000910875354 UNITS dd SHAPEPATH "data" IMAGECOLOR 255 255 255 TEMPLATEPATTERN "itasca" IMAGETYPE gif # # Projection definition, consult the PROJ.4 documentation for parameter discussion # # PROJECTION # # # "init=epsg:4326" # END # # Start of symbol definitions (we're only using a few) # SYMBOL NAME 'square' TYPE VECTOR FILLED TRUE POINTS 0 0 0 1 1 1 1 0 0 0 END END SYMBOL NAME 'circle' TYPE ELLIPSE POINTS 1 1 END FILLED TRUE END SYMBOL NAME 'star' TYPE VECTOR FILLED TRUE POINTS 0 .375 .35 .375 .5 0 .65 .375 1 .375 .75 .625 .875 1 .5 .75 .125 1 .25 .625 END END # # Start of web interface definition (including WMS enabling metadata) # WEB HEADER templates/header.html TEMPLATE "set in index.html" FOOTER templates/footer.html # change the next two lines to match your setup IMAGEPATH "C:/ms4w/tmp/ms_tmp/" IMAGEURL "/ms_tmp/" METADATA WMS_TITLE "" WMS_ABSTRACT "" WMS_ACCESSCONSTRAINTS "none" WMS_ONLINERESOURCE "http://localhost.localdomain/mapserver_demos/itasca/index.html" WMS_SRS "EPSG:4326" END END # # Start of reference map # REFERENCE IMAGE graphics/philippines-map.png EXTENT 107.145062530715 4.25623582517381 131.377985420285 21.4530688590524 SIZE 120 120 STATUS ON MINBOXSIZE 5 MAXBOXSIZE 100 COLOR 255 0 0 OUTLINECOLOR 0 0 0 MARKERSIZE 8 MARKER 'star' END # # Start of legend # LEGEND KEYSIZE 18 12 LABEL TYPE BITMAP SIZE MEDIUM COLOR 0 0 89 END STATUS ON END # # Start of scalebar # SCALEBAR IMAGECOLOR 0 0 0 LABEL COLOR 255 255 255 SIZE medium END STYLE 1 SIZE 100 2 COLOR 255 255 255 UNITS MILES INTERVALS 1 TRANSPARENT TRUE STATUS ON END # # Start of layer definitions # LAYER NAME City_Boundaries TYPE POLYGON STATUS ON DATA City_Boundaries CLASS NAME 'City_Boundaries' TEMPLATE "templates/City_Boundaries.html" STYLE COLOR 139 131 120 OUTLINECOLOR 173 255 47 END END HEADER "templates/City_Boundaries_header.html" FOOTER "templates/City_Boundaries_footer.html" TOLERANCE 3 DUMP TRUE # allow GML export METADATA WMS_TITLE "City_Boundaries" WMS_ABSTRACT "" WMS_SRS "EPSG:4326" END END # City_Boundaries LAYER NAME Barangay_Boundaries TYPE polygon STATUS OFF DATA Barangay_Boundaries TEMPLATE "templates/Barangay_Boundaries.html" HEADER "templates/Barangay_Boundaries_header.html" FOOTER "templates/Barangay_Boundaries_footer.html" CLASS NAME 'Barangay_Boundaries' STYLE WIDTH 1 COLOR 45 31 208 OUTLINECOLOR 148 109 100 END #STYLE END #CLASS END #LAYER LAYER NAME Community_Stores TYPE POINT STATUS OFF DATA Community_Stores TEMPLATE "templates/Community_Stores.html" HEADER "templates/Community_Stores_header.html" FOOTER "templates/Community_Stores_footer.html" CLASS NAME 'Community_Stores' STYLE SYMBOL 'circle' SIZE 5 COLOR 255 128 0 END #STYLE END #CLASS END #LAYER LAYER NAME Barangay_Centroids TYPE POINT DATA Barangay_Centroids STATUS OFF CLASS NAME 'Barangay_Centroids' STYLE SYMBOL 'circle' SIZE 5 COLOR 0 255 0 SIZE 3 END TEMPLATE "templates/Barangay_Centroids.html" END HEADER "templates/Barangay_Centroids_header.html" FOOTER "templates/Barangay_Centroids_footer.html" TOLERANCE 5 METADATA WMS_TITLE "Barangay_Centroids" WMS_ABSTRACT "" WMS_SRS "EPSG:4326" END END END END # Map File
For EXTENT, EPSG:4326, SYMBOL, we will find this information from following software we are going to download and install. After you save document that is explained bellow, you will find this required data in “.map” file!!!!
Like you can see, there is much to change in order for your data to be displayed on map server. This “.map” file is very important for mapserver. The mapserver looks at this file for drawing instruction. Make sure that you have correct data in this file. So save file at same location, under same name and under same extension (.map). We did not change “Itasca” name, just because we did not have enough time to do it!
So, the next step is to open “template” folder and delete everything except “footer and header.html”. You need to create additional templates for every layer. To create your templates, go to http://www.mapwindow.org/downloads/index.php?show_details=1
And download this application: MapWindowCF47SRa-x86-Setup.exe (30.3 MB - December 04 2009.)
Redistributable installer (v4.7 Stable Release) for use with plugin-based applications.
This application will help you create some templates that you need. After you install this application, open the application go to File/open/ then you need to expand dropdown menu in bottom right to select type of file you want to open. We need to select “ESRI Shapefiles(*.shp)” then you select folder where is your “data” located and select files that have “.shp” extension. If you have more than one, repeat this process. Here is screen shot:
Ok, we have data files in the application, now we have to export it! Create new folder on desktop and name it as you want. We will export those files to that location, to avoid any conflicts with original ones. Ok, now click on “Plug-Ins” menu at top, and in the list select “MapServer Generator”. The new menu will be created in top menu called “MapServer Generator”. Click on “MapServer Generator” and click on submenu called “Generate Mapfile”. The new window will open, and here we have to choose “Map File Output Path”. Select the destination folde on desktop you have created, then save it with any name you want. Next we will delete Unix User Name, Project Sub-Directory, Project Path on Server, Project Root Path on Server, and leave the rest as is! Here is the screen shot:
Click OK and ignore any warnings, because we don’t use anything else from this application except templates for now! Go to your folder on desktop and under “template” folder select your template files, but don’t copy footer and header.html. We don’t need those ones! After you copy all of the files go back to C:\ms4w\apps\mapserv-demo\templates and paste copied files. What we have to do now is to open each of this files in Notepad and insert this statement in the first line:
This is also important for MapServer to recognize this templates as MapServer templates. We are almost done with modification!
Now we have to change some html files! First we need to open file called “itasca_adds_dhtml” in Notepad or other program like Visual Studio and locate this part of the code:
So, whatever is in “RED” you have to change with your Layers names! Here I have four different Layers with names that I took from “data” folder.
You will repeat this step for: itasca_adds_frames.html, itasca_adds_pan.html, itasca_adds_scalebar.html, and itasca_basic.html
Save all files with same extension and in same place!!!
We are done and now we can go to this address and start viewing our maps!