Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
http://maps.unomaha.edu/Workshops/OpenSourceFiles/MapLab-tutorial.htm
Introduction
This document describes how to use MapLab, an open source tool for the creation of Web-mapping applications. MapLab is comprised of three components (MapEdit, MapBrowser and GMapFactory) and offers a user-friendly alternative to manually editing mapfiles and programming PHP mapscript in the creation of MapServer applications. Note: MapLab 2.2 works with MapServer version 4.0 - while mapfiles from earlier version can be accessed, all mapfiles are saved in MapServer 4.0 format. This document assumes that you are a novice user of PHP MapScript and MapLab, but have familiarity with HTML code or Web creation, as well as some GIS terminology. This document also assumes that MapLab is installed in the following directory: c:\ms4w\apps. Finally, this document assumes that you are using Internet Explorer as your browser. If you are using another browser certain functions may not appear as described in this document. This document is arranged as a tutorial and will take you through each application (MapEdit, MapBrowser, GMapFactory) by using an already existing mapfile called tutorial.map. To have an understanding of what is involved in the creation of a MapServer application without the use of MapLab, you can navigate to c:\ms4w\apps\maplab-2.2\tutorial and open up the file tutorial.phtml in Notepad or TextPad.
MapLab
Once you have MapLab installed and configured you may go ahead and start Internet Explorer. Once your browser is opened, type in the following in the address bar: http://<server>/maplab/ and hit Enter on your keyboard. This will bring you to the MapLab introduction page. Here, you will see links to all three components of MapLab (MapEdit, MapBrowser and GMapFactory) and a description of what each one of them does. Read the descriptions. Look at the first four buttons on the toolbar (top left hand corner). These four buttons, known as MapLab MapBrowser program.) and GMapFactory , MapEdit ,
, are a means of navigating to the various programs. (You will find them in the upper left-hand corner in each
1 of 12
15/09/2011 9:38
MapLab - tutorial
http://maps.unomaha.edu/Workshops/OpenSourceFiles/MapLab-tutorial.htm
We will begin this tutorial by first exploring MapEdit. Click on the MapEdit heading or on the MapEdit button
in the toolbar.
MapEdit
MapEdit is a tool for creating, editing, and managing mapfiles.
Opening/Importing a Mapfile
MapEdit works with files called mapfiles which are the basic configuration mechanisms for MapServer. We are going to open an already existing
2 of 12
15/09/2011 9:38
MapLab - tutorial
http://maps.unomaha.edu/Workshops/OpenSourceFiles/MapLab-tutorial.htm
mapfile called tutorial.map to conduct this tutorial. Move your cursor to the File Menu dropdown , click on the down arrow, and select the Open Map ... option. The Open File window will appear. Navigate your way to the file tutorial.map, this is located at c:\ms4w \apps\maplab-2.2\tutorial\. Click on tutorial.map and then click on the Open button .
If you look in the Object Browser (the area on the left-hand side) you will see all the objects listed that make up this mapfile. Right now you are on the Map Object. You will know this because of two clues. The first clue is that the Map Object appears in a darker color in the Object Browser and the second clue is that you will see the name "Map" in the top left corner of the Object Properties Frame (the area on the right-hand side). The Map Object is responsible for defining the application-wide parameters, and is therefore a very important piece in building a mapfile. You can find out more information about the Map Object and the other objects in a mapfile by clicking on the Help button and going to Mapfile Reference v4.0. The Object Properties Frame contains all the information for building the Map Object, you will see several parameters listed in this frame! for the Map Object. Try clicking on the other Objects listed in the Object Browser to see what their parameters are. You can find out more information about what each of these parameters are by clicking on the Help button and going to the Mapfile reference v4.0. The Open Map ... option only allows you to access mapfiles written in v4.0 of MapServer. If you have mapfiles written in an earlier version of MapServer, you must use the Import 3.x Map ... option from the File Menu dropdown. Try importing the file tutorial36.map, which is also located at c:\ms4w\apps\maplab-2.2\tutorial\. A warning will appear telling you that certain formatting (e.g., comments) in your older file will be lost once it is saved again, and that it would be best for you to save a copy of the original file.
Previewing a Mapfile
Now that you have had a chance to explore the different Objects and their parameters that make up a mapfile, let's see what type of map it makes. 1. In the main toolbar click on the Preview map button . Another window will appear in your browser with a map of Canada. We will explore this map of Canada. 2. Go to the Legend and click on the empty box next to Grid so that a check mark appears. Now click on the Redraw Map button , which is at the bottom of the Legend. Lines of latitude and longitude will appear over the map. Experiment with turning on and off other layers in the legend. Remember to click on the Redraw button to view your changes.
3. Go to the ROSA applet (on the right-hand side of the map) and you will see various tools for exploring your map. These buttons can be turned on or off by clicking on them You will know that a button is on when it is a light blue color and it will be off when it is a dark blue color . By default the Zoom in button is always on when you first preview the map (so it is a light blue color). Since this button should be on (check to see if it is light blue) drag a rectangular box around the area you want to zoom in to and watch as your map reloads and zooms into that area.. Explore with the Recenter button to recenter the location of your map. Zoom out with the Zoom out button . . You can also zoom back to the full map size! by clicking on the Zoom to full extents button 4. Zoom into an area on the map of Canada. Go to the keymap
and you will see that a little red box outlines the area of Canada
that you are zoomed into. Click on an area of Canada on the keymap. What happens? You will notice that the main map moves with the location of the red box. 5. You may also want to experiment with the scale of the map. You can do this by going to the box titled map scale and change the number in that box. Smaller numbers will zoom you into the map, larger numbers will zoom you out of the map. 6. You can also experiment with changing the extents of the map. Adjust the numbers in the min x and y and the max x and y boxes to see how it affects the map. Remember you can always click on the Zoom to full extents button to bring you back to the defaults. 7. Close the window with the tutorial preview and return to MapEdit. Now that you know what the map looks like we are going to make a few changes.
Saving a Mapfile
The first change we are going to make is to save our mapfile under a different name. This way you will have a separate copy from the original. 1. Click on the File Menu dropdown and select the Save Map As ... option. Once the Save As window appears, navigate to c:\ms4w \apps\maplab-2.2\tutorial. You must save your mapfile in this directory as the mapfile uses relative paths. If you attempt to save your file in a different directory you will receive a JavaScript alert warning you to check SYMBOLSET, FONTSET and SHAPEPATH. If you choose to save the mapfile in a new directory you must change these paths.
3 of 12
15/09/2011 9:38
MapLab - tutorial
http://maps.unomaha.edu/Workshops/OpenSourceFiles/MapLab-tutorial.htm
2. Name this file mymap (no spaces). Now click on the Save button . 3. Now every time you wish to save your mapfile, you can click select the Save Map option from the File Menu dropdown.
4 of 12
15/09/2011 9:38
MapLab - tutorial
http://maps.unomaha.edu/Workshops/OpenSourceFiles/MapLab-tutorial.htm
1. Click on the Map Object in the Object Browser. Make sure you have the Map Object selected. 2. Use the drop down menu in the tool bar and change Create New Object to Layer Object. Click on the Add new item button new layer object. to add a
3. You will notice that a new layer appears at the bottom of the Object Browser, it is called layer(). We are going to use this layer to re-add the bathymetry layer. Click on it now. 4. The first step is to add the bathymetry file to the layer. Go to the parameter called Data and type bath_mapserver.tif. 5. Now, we must give this layer a name. This name will appear in the Object Browser as well as the Legend, so you will want to give layers name that accurately describe what they show. Go to the Name parameter and type in bathymetry in the empty field. 6. We must also say whether we want this file to be automatically on when someone visits the map, or whether we would like it off and have the users turn it on in the legend (remember the check mark?). We are going to make the bathymetry layer be automatically on. Go to the Status parameter and using the drop down menu, select On.
7. The next step is to describe what type of data this is. As mentioned previously, this is raster data, so go to the parameter named Type and using the drop down menu select Raster. 8. Select Save Map. 9. Let's have a look at your map now. Click on the Preview map button. You may notice that your bathymetry layer now covers all the other layers. This is because of two reasons, one is because the spatial coverage of the layer and the other is its placement in the Object Browser. Since the bathymetry layer covers all of Canada, it will hide some of the other smaller layers, therefore we need to place the layer so that the other layers overlay on top of it. Currently, our bathymetry layer is on top of all the others, hiding them. The reason for this is because when MapEdit builds our map it builds the objects from top to bottom as listed in the Object Browser, since the bathymetry layer is on the bottom, it gets built last, meaning it is the last layer to be placed on the map. 10. We need to move the bathymetry layer up so that it is the first layer listed in the Object Browser (i.e., above the land_fn layer). Click on the . You will notice that with one click it has moved up in the Object bathymetry layer to select it. Now click on the Promote Object button Browser. Keep clicking on the Promote Object button until it is above the land_fn layer (foreign land) and below the Scalebar Object. If you need to you can use the Demote Object button to move the bathymetry layer down. 11. Select Save Map. 12. Click on the Preview map button to see what the map looks like now that you have moved the bathymetry layer. You should see that the other layers are now visible. Close the Map Preview window. 13. The final step is to add metadata to our layer. Click on the bathymetry layer so that it is selected. Go to the toolbar and using the drop down menu change Create New Object to Metadata Object. Click on the New item button . You should see a metadata layer appear below the bathymetry layer. 14. Click on the metadata layer. We need to add some information to the metadata. To do this, use the drop down menu and change it to Add new metadata and click on the New item button. Under the heading parameter type Description and under the heading value type Elevation/Bathymetry. Now click on the Apply Changes button. 15. Select Save Map. .
Adding Layer Objects (with Vector Data) We will now re-add the popplace layer to our map. As you will remember, popplace is composed of vector data and therefore it contains some objects that the bathymetry layer does not. We will also make changes to this layer so that only Ottawa, the capital of Canada is displayed. 1. We need to add the popplace data to our mapfile. Use the same method you did before to add a new layer object. If you have forgotten, please refer back in the notes. 2. Click on the new layer at the bottom of the Object Browser. Once the properties for that layer opens, click on the Select a File button next to the Data Type parameter. The Open File window will appear and will immediately take you to the data folder for mymap.map. Here, you will see all the shapefiles used in this mapfile. Click on popplace.shp and then click OK.
5 of 12
15/09/2011 9:38
MapLab - tutorial
http://maps.unomaha.edu/Workshops/OpenSourceFiles/MapLab-tutorial.htm
3. Instead of naming this layer popplace we are going to change the name to capital. In the Name parameter type capital. 4. Now we must decide whether or not we want this data to be on or off. In this case we want this data to be off and the user will have to turn it on in the legend. Go to the Status parameter and using the drop down menu choose off. 5. Finally, we must specify what type of data this is. Since this is vector data we must indicate whether or not this data comes in the form of points, lines, or polygons. The popplace.shp is a point, so using the drop down menu choose point.
6. Since we want the capital layer to be one of the last layers drawn on the map, its location in the Object browser is fine. We, therefore, do not need to promote it. 7. Select Save Map from the File Menu dropdown. 8. Click on the Preview Map button and see what the changes have done. Click in the empty box next to capital in the legend and click on the Redraw map button . Did the capital appear? It did not appear because we have not classified the data. As mentioned previously, all vector data need class Objects. Adding Class Objects In this next section you will learn how to add class Objects to vector layers. 1. Click on the capital layer so that it is selected. Use the drop down menu in the toolbar and change Create New Object to Class Object. Now click on the Add new item button. You should see a class object appear underneath the capital layer. 2. We need to give the class a name that indicates what it being classified. Since we are going to classify this layer so that it only shows the capital of Canada type capital in the Name parameter. 3. The popplace.shp file contains information on many of the cities of Canada, however we only want Ottawa to be displayed on our map. To do this you need to add information to the Expression parameter so that only Ottawa is visible. To find out what type of information we need to add, you can open up the popplace.dbf file in a GIS program or a spreadsheet program like Excel. Once you are in one of these programs, navigate to c:\ms4w\apps\maplab-2.2\tutorial\data\ and open up popplace.dbf. The table that opens contains all the information for the popplace.shp. Look for the heading Name and either scroll down until you find Ottawa or do a find for Ottawa. Once you have found Ottawa look for the heading Capital. All cities are categorized in this heading as either a 0 (non-capital) a 1 (national capital) or a 2 (provincial capital). You will see that Ottawa is categorized as a 1. Close the spreadsheet program or the GIS program you were usin! g and return back to MapEdit. 4. Since the number 1 represents national capitals (hence Ottawa), go to the Expression parameter and type in 1. 5. Select Save Map from the File Menu dropdown to save the changes. 6. We also need to provide a symbol to mark Ottawa on the map, and in order to do this you must use a STYLE object, which is described in the next section. Adding a Style Object to a Class In order to specify colours and symbols for layers, a STYLE object must be added. 1. Click on the 'capital' CLASS object so that it is selected in the Object Browser. Use the drop down menu in the toolbar and change Create New Object to Style Object. Now click on the Add new item button. You should see a style object appear underneath the capital class. 2. Go to the Symbol parameter and click on the Select a symbol button you would like to represent Ottawa and then click OK. . The Symbol picker window will appear. Click on a symbol that
6 of 12
15/09/2011 9:38
MapLab - tutorial
http://maps.unomaha.edu/Workshops/OpenSourceFiles/MapLab-tutorial.htm
3. Now we need to select a color for our symbol. Go to the color parameter to pick a color. You can either enter in numbers or you can click on the Select a color button .
4. Once you have chosen a color, look at both the symbol and color parameter and you will notice their buttons display the color and symbol you picked. 5. The final step is to choose the size of your symbol. Scroll down the Object Properties frame until you see a parameter called Size (it is below the backgroundcolour parameter). In the empty field type 12. 6. Select Save Map from the File Menu dropdown. Selecting the ClassItem Field To classify an layer based on a certain attribute, you must specify the field to classify. 1. Return to the capital LAYER object by clicking it in the Object Browser. 2. Scroll down the list of parameters in the Object Properties Browser until you see a parameter called ClassItem. In this parameter we need to indicate what heading in the .dbf file we are using to classify our capitals. As you will recall the heading we used was called Capital. You can either type the name capital into the ClassItem parameter or click on the Select a file button. The Shape file attribute picker window will open. Scroll down until you see the heading capital, click on it and click OK.
3. Select Save Map from the File Menu dropdown. 4. Now click on the Preview map button and turn the cities layer on in the legend. You will see a symbol for Ottawa along the Quebec/Ontario broader. Adding Labels to a Class Object There is one missing piece to our map. We should add a label to show the name of the capital city of Canada. 1. Click on the Class Object underneath the capital layer. Use the drop down menu in the toolbar and change Create new object to Label Object. Click on the Add new item button. 2. Now click on the Label Object that appears underneath the Class Object. 3. The first thing we need to do is to pick a font that we want our label to be written in. Click on the Select font The Font picker window will appear. There are several fonts listed, pick one that you think is appropriate. button.
7 of 12
15/09/2011 9:38
MapLab - tutorial
http://maps.unomaha.edu/Workshops/OpenSourceFiles/MapLab-tutorial.htm
4. Now we need to determine whether this font is truetype or bitmap. Go to the Type parameter and using the drop down menu choose truetype. 5. Next, we need to decide where we want to position the label on the map. Go to the parameter called Position and using the drop down menu choose Auto. You can read up on what the other position do by clicking on the Help button and choosing MapServer reference v3.6.
6. Go to the parameter called Size, here we will choose the size of the font. You can do this in two ways. You can either use the drop down menu and choose from the sizes listed there (small, medium, large etc.) or you can type a number in the box titled integer. In the box titled integer enter in the number 8 7. 8. 9. 10. 11. 12. 13. 14. and choose a color for your font. We now need to give our font a color. Go to the color parameter and click on the Select a color button Select Save Map from the File Menu dropdown. Click on the Preview map button to see what your map looks like now. Do not forget to turn on the capital layer. You may have noticed that the label does not appear on your map, this is because we have one more step to complete. We need to tell our capital layer which field to use to get the name of our city. Click on the capital layer to open it up. Scroll down the Object Properties Frame until you see a parameter called LabelItem. Click on the Select a file button and click on Name. If you remember from the popplace.dbf file the name Ottawa was located underneath the Name heading. Now select Save Map from the File Menu dropdown. If your preview your map you should see the label.
MapBrowser
MapBrowser allows you to select spatial data from local and WMS servers.
8 of 12
15/09/2011 9:38
MapLab - tutorial
http://maps.unomaha.edu/Workshops/OpenSourceFiles/MapLab-tutorial.htm
Opening a Mapfile
1. If you are in MapEdit, click on the MapBrowser button . If you had the mymap.map file open, this file will automatically be displayed in MapBrowser. 2. If you are not in MapLab go there now and click on the MapBrowser heading. To open a file select the Open Map ... option from the File Menu dropdown . Navigate to the directory that contains mymap.map. Click on it and click Open.
Exploring MapBrowser
Let's take a moment to explore MapBrowser. 1. You can use the arrows surrounding the map to move the map to the north, south, east and west.
2. To return the map back to the initial view, click on the Zoom to Initial View button on the ROSA applet. 3. You can also use the Zoom in and Zoom out button to explore the map. Like the preview map in MapEdit, these buttons can be turned on or off. You will know that the Zoom in button is on when it is a light blue color and it will be off when it is a dark blue color . To zoom into an area, click on the Zoom in button so it is a light blue color. Drag a rectangular box around the area you want to zoom in to and watch as your map reloads and zooms into the area you chose. 4. Another interesting feature of MapBrowser is that you can set a custom view. This feature is useful if the map layer you are adding has a much smaller extent than the map. Instead of continually searching and zooming into the map layer you can set the custom view to easily view that map layer. Zoom into Newfoundland and click on the Set Custom view button applet to return to the full map. If you click on the Zoom to custom view button . This sets your custom view so you can return to in the ROSA in the ROSA applet, you will return to Newfoundland. Newfoundland after you have zoomed in and out of other areas on the map. Now click on the Zoom to Initial View button
Adding a Layer
Before we can add a layer we must first install a server, where we can obtain different map layers to add to our map. 1. We are going to add a layer from one of the WMS servers. The first thing we need to do is connect to a WMS server. Click on the Manage servers button . The Manage Servers window will open. 2. If you look in the Available Servers box you will see that there are several servers available to you. However, we will add the DM Solutions Group's WMS server from where you will obtain data. To do this type the following URL in the URL field: http://www2.dmsolutions.ca /cgi-bin/mswms_gmap?. Then click the Add Server button . You should see in the Available Servers box that the GMap WMS Demo Server has been added to the list of available servers. A (c) will be next to the server name indicating that you are connected to that server. Click on the Close button . 3. If you look in the data stores section of MapBrowser (bottom left-hand corner), you will see that GMap WMS Demo Server has been added. Click on the plus symbol next to this server. 4. GMap WMS Demo Server will appear underneath, click on the plus symbol next to its name. When you do, you should see the following layers listed below:
9 of 12
15/09/2011 9:38
MapLab - tutorial
http://maps.unomaha.edu/Workshops/OpenSourceFiles/MapLab-tutorial.htm
5. Most of these layers are already on your map. However, the one layer that is not is the parks layer. Click on the parks layer to add it and then click the Apply button .
6. You may notice that nothing happened and that an Alert symbol appeared in the upper left-hand corner of MapBrowser. Click on the Alert symbol to open up the Errors Occurred window. The error message tells us that the projection has not been set. For layers to be added in MapBrowser, a Projection Object must be added to the mapfile.
5. Select the Save Map option from the File Menu dropdown. 6. We are now ready to return to MapBrowser. Click on the MapBrowser button in the toolbar.
button . 2. You will notice that the parks layer appears above the capital layer in the legend. The radio button next to the layers tells us whether or not the layer is active. If a dot appears in the radio button it means it is active and can be manipulated . The box next to the layer tells us whether or not the layer is visible on the map. If a check mark appears in the box the layer is visible . 3. Looking at our parks layer, we can see that the layer is visible. For example, we can turn off the parks layer by clicking on the layer visibility box and removing the check mark. To make this change click on the Apply button. 4. We can also see that our layer is active. When a layer is active we can manipulate it. For example, because the parks layer is active we can use the Promote and Demote buttons to move the layer up and down. Or use the Delete active layer button to delete the layer. You may notice that the layers in MapBrowser are listed differently than in MapEdit. Here, the layers to be drawn first are at the bottom and the layers to be drawn last are at the top. Since we do not want parks to be the first layer drawn on the map (where it might hide other layers), we should demote it. Use the Demote button to move the parks layer from the top to above the land_fn (foreign land) layer and below the drain_fn (foreign drainage layer). 5. You may also notice that there is an information button next to the parks layer. This informs us that this layer is queriable. Turn on the . Go to the ROSA applet on the map and click on the Point query button visibility of the parks layer and click the Apply button Now click on one of the parks, you should see tiny cross hairs on the park. The Query results window will appear providing information about the park, like the park name and its area. 6. Select Save Map from the File Menu dropdown. .
GMapFactory
GMapFactory is a tool for rapid creation and deployment of mapping applications. In this tool you will be able to assemble all the parts to create your Web mapping application such as: the mapping tools to use (i.e., ROSA applet), the layout of the application, and the design of the application.
10 of 12
15/09/2011 9:38
MapLab - tutorial
http://maps.unomaha.edu/Workshops/OpenSourceFiles/MapLab-tutorial.htm
2. Click on the link called select existing next to the project field. This will open up the GMapFactory window. In the top of the window will be a path describing the location of the project. Make a note of this location. Close the GMapFactory window. In the project field type mymap_project and click OK. This will be the name of your folder. You can now move on to the section titled Creating Your Application. 3. If you are not in MapLab or do not have mymap.map open, go to MapLab now and click on the GMapFactory heading. When GMapFactory opens, click on the Open existing file button in the toolbar. The GMapFactory window will appear. Where it says Application name, and navigate to where your mymap.map file is
type mymap_project. Where it says Map File click on the Browse button located. Click on it and then click OK.
2. In the map title section, you can decide whether or not you want a title by clicking the box next to map title to remove the check mark. For this tutorial leave the map title visible. In the text box type in Map of Canada. This will be the title that appears on our mapping application.. The drop down box next to size determine the size of font you want to use for your title. You can also pick the color of the font for your title and its position on the application. Experiment with all three of these functions.
3. The legend section affects what the legend will look like in your application. Like the map title section you can choose whether or not to have your legend visible by clicking on or off the check mark. The User Groups box allows you to enable groups in your legend display, for example you can create the group water and under water list the layers rives, lakes and oceans. However, to enable user groups you must set up groups in the mapfile. Since we have not done this, we will leave this option alone. You can also decide the location of the legend on your application.
11 of 12
15/09/2011 9:38
MapLab - tutorial
http://maps.unomaha.edu/Workshops/OpenSourceFiles/MapLab-tutorial.htm
4. In the scale bar section and key map section you can use the drop down menu to determine their locations on the map.
5. In the mapping tools section you can decide which tools you want in your application. For example, you may decide that you do not want the ROSA applet but you only want HTML tools displayed. You can also click on or off the various tools, like the zoom in button to determine whether or not you want them on your application. In the Zoom factor box you can decide how far the zoom in or zoom out button will zoom. If you are using HTML tools instead of the ROSA applet, you can use the drop down menu to decide where to position them on your map.
6. In the pan arrow section you can decide whether or not you want your pan arrows to surround the map or be assembled into a compass rose. If you chose the compass rose you can also decide where you would like to place it on your map by using the drop down menu.
7. Look at the heading called order, which is in each of the sections, and you will see up and down arrows. They are called the Promote button and the Demote button . These buttons change the order of the objects in the same column. For example if you have the legend and the keymap position in the left column you can use the promote and demote buttons to move the legend above the keymap. 8. Once you have your application assembled, click on the URL on the top right of the GMapFactory page to go to your new MapServer application. 9. There is one final correction to make on your application. If you look at your parks layer you will see it is oddly named in the legend. To provide this layer with a more proper name return back to MapEdit by clicking on the MapEdit button . 10. When MapEdit opens, find the layer GMap_WMS_Demo_Server-park layer in the Object Browser and click on it. In the Name parameter change the name to park. 11. Click Save. 12. Now return to GMapFactory. You will see that the parks layer is now properly named. Congratulations, your application is now ready to be published on the Web.
12 of 12
15/09/2011 9:38