@@ -13,6 +13,7 @@ import java.awt.Color
1313import java.awt.Font
1414import java.awt.FontMetrics
1515import java.awt.Graphics2D
16+ import java.awt.Point
1617import java.awt.Rectangle
1718import java.awt.font.LineBreakMeasurer
1819import java.awt.font.TextAttribute
@@ -95,7 +96,11 @@ class Java2DCartoBuilder implements CartoBuilder {
9596
9697 @Override
9798 CartoBuilder northArrow (NorthArrowItem northArrowItem ) {
98- drawNorthArrow(northArrowItem)
99+ if (northArrowItem. style == NorthArrowStyle.North ) {
100+ drawNorthArrow(northArrowItem)
101+ } else if (northArrowItem. style == NorthArrowStyle.NorthEastSouthWest ) {
102+ drawNESWArrow(northArrowItem)
103+ }
99104 this
100105 }
101106
@@ -146,6 +151,93 @@ class Java2DCartoBuilder implements CartoBuilder {
146151 graphics. draw(path2)
147152 }
148153
154+ private void drawNESWArrow (NorthArrowItem northArrowItem ) {
155+
156+ int x = northArrowItem. x
157+ int y = northArrowItem. y
158+ int width = northArrowItem. width
159+ int height = northArrowItem. height
160+
161+ if (northArrowItem. drawText) {
162+ graphics. color = northArrowItem. textColor
163+ graphics. font = northArrowItem. font
164+ FontMetrics fontMetrics = graphics. fontMetrics
165+ int textWidth = [fontMetrics. stringWidth(" N" ), fontMetrics. stringWidth(" E" ), fontMetrics. stringWidth(" S" ), fontMetrics. stringWidth(" W" )]. max()
166+ int textHeight = fontMetrics. height
167+ drawString(" N" , new Rectangle ((width / 2 - textWidth / 2 ) as int , 0 , textWidth, textHeight), HorizontalAlign . CENTER , VerticalAlign . TOP )
168+ drawString(" E" , new Rectangle (width - textWidth, (height / 2 - textHeight / 2 ) as int , textWidth, textHeight), HorizontalAlign . RIGHT , VerticalAlign . MIDDLE )
169+ drawString(" S" , new Rectangle ((width / 2 - textWidth / 2 ) as int , height - textHeight, textWidth, textHeight), HorizontalAlign . CENTER , VerticalAlign . TOP )
170+ drawString(" W" , new Rectangle (0 , (height / 2 - textHeight / 2 ) as int , textWidth, textHeight), HorizontalAlign . LEFT , VerticalAlign . MIDDLE )
171+ x = x + textWidth
172+ y = y + textHeight
173+ width = width - (textWidth * 2 )
174+ height = height - (textHeight * 2 )
175+ }
176+
177+ Point north = new Point ((x + (width / 2 ) as int ) - 2 , y)
178+ Point east = new Point (x + width, y + (height / 2 ) as int )
179+ Point south = new Point ((x + (width / 2 ) as int ) - 2 , y + height)
180+ Point west = new Point (x, y + (height / 2 ) as int )
181+
182+ Point mid = new Point (x + (width / 2) as int, y + (height / 2 ) as int )
183+
184+ Point northEast = new Point (x + (width * 2 / 3) as int, y + (height * 1/ 3 ) as int )
185+ Point southEast = new Point (x + (width * 2 / 3) as int, y + (height * 2/ 3 ) as int )
186+ Point southWest = new Point (x + (width * 1 / 3) as int, y + (height * 2/ 3 ) as int )
187+ Point northWest = new Point (x + (width * 1 / 3) as int, y + (height * 1/ 3 ) as int )
188+
189+ // Fill
190+ graphics. color = northArrowItem. fillColor1
191+ graphics. fill(createPolygon(north, northEast, mid))
192+ graphics. color = northArrowItem. fillColor2
193+ graphics. fill(createPolygon(north, northWest, mid))
194+
195+ graphics. color = northArrowItem. fillColor1
196+ graphics. fill(createPolygon(east, southEast, mid))
197+ graphics. color = northArrowItem. fillColor2
198+ graphics. fill(createPolygon(east, northEast, mid))
199+
200+ graphics. color = northArrowItem. fillColor1
201+ graphics. fill(createPolygon(south, southWest, mid))
202+ graphics. color = northArrowItem. fillColor2
203+ graphics. fill(createPolygon(south, southEast, mid))
204+
205+ graphics. color = northArrowItem. fillColor1
206+ graphics. fill(createPolygon(west, northWest, mid))
207+ graphics. color = northArrowItem. fillColor2
208+ graphics. fill(createPolygon(west, southWest, mid))
209+
210+ // Stroke
211+ graphics. color = northArrowItem. strokeColor1
212+ graphics. draw(createPolygon(north, northEast, mid))
213+ graphics. color = northArrowItem. strokeColor2
214+ graphics. draw(createPolygon(north, northWest, mid))
215+
216+ graphics. color = northArrowItem. strokeColor1
217+ graphics. draw(createPolygon(east, southEast, mid))
218+ graphics. color = northArrowItem. strokeColor2
219+ graphics. draw(createPolygon(east, northEast, mid))
220+
221+ graphics. color = northArrowItem. strokeColor1
222+ graphics. draw(createPolygon(south, southWest, mid))
223+ graphics. color = northArrowItem. strokeColor2
224+ graphics. draw(createPolygon(south, southEast, mid))
225+
226+ graphics. color = northArrowItem. strokeColor1
227+ graphics. draw(createPolygon(west, northWest, mid))
228+ graphics. color = northArrowItem. strokeColor2
229+ graphics. draw(createPolygon(west, southWest, mid))
230+ }
231+
232+ private GeneralPath createPolygon (Point point1 , Point point2 , Point point3 ) {
233+ GeneralPath path = new GeneralPath (GeneralPath . WIND_EVEN_ODD , 3 )
234+ path. moveTo(point1. x as int , point1. y as int )
235+ path. lineTo(point2. x as int , point2. y as int )
236+ path. lineTo(point3. x as int , point3. y as int )
237+ path. closePath()
238+ path
239+ }
240+
149241 @Override
150242 CartoBuilder text (TextItem textItem ) {
151243 graphics. color = textItem. color
0 commit comments