Sunday, 9 August 2015

More on Styling Line features in TileMill


In this post, we will use line feature layers-roads and rail line to design a map project in TileMill.

Download Sample data here- Line features
(attribute data to www.mapsnigeriainitiative.blogspot.com)

Launch TileMill and create a new project.
Click the Layers icon > Add to import the line feature layers that represent the different classes of roads and rail line.
Capture-35

In the Layers window, three classes of roads namely Major, Minor and Secondary roads as well as a rail line were added into the TileMill project- .
A look at the Style.mss window also shows the different default codes assigned to each layer.
Capture-41

image In the railine style, an additional line of code- line-dasharray:5,3; is added to style the railline as dashed lines. This will help clearly differentiate the railline from the roads.The screenshot below shows the changes reflected in the style of the railline feature due to this additional line of code.
Capture-42

Next extra lines of code defining which features should appear at certain zoom levels is added to the style layers. With the understanding that a lot lines can crisscross and intersect each other, turning some off at certain zoom levels will give a neater view to the map user when zooming in and out of the map.
The Style.mss codes for each layer indicates the following:
image major roads line width increases from 3 to 5 as the zoom level moves from 8 to 10. The line width stays as 5 anything above or equal to 12.
imageThe  Interesting part is the railline style layer that specifies that it only appears on the map between zoom greater or equal to 13 and less than or equal to 15 with a line width of 5. Look at the screenshot below and one can see that at zoom 12 (reb boxed to the upper left) the railline is not appearing on the map.
Capture-49

But on moving the zoom up to 13 (red boxed to the upper left of the screenshot), the railline appears on the map as instructed in the code.
Capture-50

Another important part of working with line features is to label them with proper names like street names etc.
image We insert this layer of code in the style.mss window allocating labels to the roads based on an attribute field that contains this values. Note that in the second line- text-name: [blank];. this blank space will have to be filled with the attribute field name.
For the demo, the attribute field name is ‘Name’, as seen on the screenshot. The Features window can be opened by clicking the features icon beside the layer in the Layers window.
Capture-51


image Note that two extra lines of code have been added to the previous style layer. text-dy is to displace the label upwards 12 pixels while the text-max-char-angle-delta allocated the angle the label will bend towards at the point of placement.
From the screenshot, one can observe that the labels (red boxed on the map canvas) are well aligned with the line features now.
Capture-54


In this brief tutorial, we have been able to show you how to style your lines into dashed or straight lines, hide and/or show different lines at different zoom levels as well as label the line features.

Wednesday, 5 August 2015

Styling Line features in TileMill


The previous post showed us how to style line features using TileMill. This post will further demonstrate how to apply enhanced cartographic styles to line features using a different dataset.

Download sample datasets here- Highways.shp , Rail.shp

Open a new project in TileMill and fill in a Filename, name and description as below on the screenshot.
Capture-1

Click on the Layer icon (red boxed below) and Click on the Add layer to add the first sample data- nigeriahighway.shp
Capture-2

On the screenshot, the sample data is added along with a corresponding default layer in the style.mss window.
Capture-3

Click on the features icon beside the sample data to display the attributes of the dataset. There is an attribute field-TYPE-that classifies the different kind of roads. We will use this different values as we move along.
Capture-4

image The Circular red boxed lines of code is the default style that TileMill allocated to the dataset when it was added. Write the lines of code in red box below it in your style.mss window. The new lines of code are allocating a ::case to the lines which are of type-primary on the attribute table. On the screenshot, the line features which are classified as ‘primary’ have now have width and with different line and fill colour.

Capture-5

image Next, we do the same for the class of roads –‘secondary’. This time line-width is smaller and the color of the line and fill are different. Most importantly note the extra line of code line-dasharray: 10,3; is added to make the line feature appear as dashed lines.See the screenshot -the red arrow indicates the line features represented by the new style.
Capture-7

Add the second sample data to the layer window- ngarails. To improve the visibility of the line feature, we edited the default style layer by changing the line-width to 3 and the line-color to image.
Capture-8

image Write out this lines of code below the default style. These lines of code will style the railway line with a dashed look which is quite popular as a cartographic style. See screenshot below for what the line feature should look like after saving the style. The red arrow points from the style (red boxed) to the railway line feature on the map.
Capture-10

We hope you enjoyed the post. Feel free to let us have your comments and feedback.

Sunday, 2 August 2015

Labeling Markers in TileMill


Today  the post will demonstrate how to label markers or points using TileMill.
The task is to use the attribute values of a point layer to label the markers on the map. In addition, these labels will be placed right within the markers.

Download the sample data here- https://www.dropbox.com/s/yz13dsnje27ykft/OccurClay.csv?dl=0

Launch TileMill and Create a new project. Click on Layer icon (red boxed 1) and then Add layer. Add the Sample dataset (red boxed 2) and the style is also created on the style.mss window.
Capture-1

Click on the features icon of the new vector layer and inspect the attribute table. The values to be used for the labeling are inside the attribute field-PH.
Capture-2


image We made the following changes to the default styles. Take a look at our changes and edit the corresponding lines of code on the style.mss window. The edits will change the color of the map background, increase the marker size and color as well give it opacity. The screenshot below is an example of what the map window should look like after the editing of the default CartoCSS codes. Remember to Click Save to effect the changes.
Capture-3


image Write these lines of code as a new layer in the style.mss window and click Save. This lines of code will add values in the attribute field-PH as labels within the circular marker symbols. See screenshot below for the example of how the map should look. Now the attribute values from the PH attribute field are inside their corresponding marker symbols.
Capture-4

In this few steps, we have demonstrated how to label your markers with values from an attribute field using TileMill.
Thank you for following the blog.