Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a simple map scale bar in geotools

Using GeoTools I was able to display a simple shape file using JMapPane class. My requirement is to draw a bar much like in any maps that shows the scale of the map on display in meters in relation to the length of the bar as I zoom in/out.

I've been searching for days now and I just couldnt find any concrete hint.

Even a way to convert two given points in a map to distance in pixels would really help me

Please any hint is greatly appreciated.

like image 957
user1315938 Avatar asked Dec 21 '25 10:12

user1315938


1 Answers

I don't have an example, but for this use case, if you are on GeoTools 8.x, you should implement your own DirectLayer (http://docs.geotools.org/latest/userguide/library/render/map.html). Code to generate a scale bar can be found in uDig (LGPL, but don't know exactly in which class) or in GeoServer (GPL'd, here: http://svn.codehaus.org/geoserver/trunk/src/wms/src/main/java/org/geoserver/wms/decoration/LegendDecoration.java)

like image 193
Andrea Aime Avatar answered Dec 23 '25 23:12

Andrea Aime



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!