Khảo sát gói thư viện mã nguồn mở Geotools và ứng dụng hiện thực hệ thống thông tin địa lý trên nền Web



tải về 5.55 Mb.
trang19/34
Chuyển đổi dữ liệu16.10.2017
Kích5.55 Mb.
#33732
1   ...   15   16   17   18   19   20   21   22   ...   34

Xây dựng, quản lý các lớp bản đồ


Sau khi đã có được thông tin từ dạng FeatureSource và kiểu hiển thị của feature source ta hoàn tất việc chuẩn bị hiển thị.

Tạo lớp MapLayer để chứa dữ liệu địa lý của đối tượng và cách thể hiện của nó thông qua lớp DefaultMapLayer là hiện thực của interface MapLayer.

MapLayer layer = new DefaultMapLayer(featureSource, style);

Sau khi tạo ra các mapLayer ta tích hợp các lớp này vào trong 1 mapContext thông qua phương thức addLayer(), phương thức này có khả năng nhận vào featureSource và style để tự động tạo thành MapLayer trong ContextMap hoặc nhận vào MapLayer đã được tạo trước từ featureSource và style.

MapContext mapContext = new DefaultMapContext();

mapContext.addLayer(featureSource, style);



hay

mapContext.addLayer(layer);



MapContext cung cấp các hàm giúp cho việc quản lý các lớp dữ liệu như:

Method Summary

 void

addLayer(FeatureCollection collection, Style style)
          Add a new layer and trigger a LayerListEvent.

 void

addLayer(FeatureSource featureSource, Style style)
          Add a new layer and trigger a LayerListEvent.

 boolean

addLayer(int index,MapLayer layer)
          Add a new layer in the specified position and trigger a LayerListEvent.

 boolean

addLayer(MapLayer layer)
          Add a new layer if not already present and trigger a LayerListEvent.

 int

addLayers(MapLayer[] layers)
          Add an array of new layers and trigger a LayerListEvent.

 void

addMapBoundsListener(MapBoundsListener listener)
          Register interest in receiving MapBoundsEvents.

 void

addMapLayerListListener(MapLayerListListener listener)
          Register interest in receiving a LayerListEvent.

 void

addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Registers PropertyChangeListener to receive events.

 void

clearLayerList()
          Clears the whole layer list.

 java.lang.String

getAbstract()
          Get the abstract which describes this interface, returns an empty string if this has not been set yet.

 com.vividsolutions.jts.geom.Envelope

getAreaOfInterest()
          Gets the current area of interest.

 java.lang.String

getContactInformation()
          Get the contact information associated with this context, returns an empty string if contactInformation has not been set.

 org.opengis.referencing.crs.CoordinateReferenceSystem

getCoordinateReferenceSystem()
          Get the current coordinate system.

 java.lang.String[ ]

getKeywords()
          Get an array of keywords associated with this context, returns an empty array if no keywords have been set.

 MapLayer

getLayer(int index)
          Return the requested layer.

 com.vividsolutions.jts.geom.Envelope

getLayerBounds()
          Get the bounding box of all the layers in this MapContext.

 int

getLayerCount()
          Returns the number of layers in this map context

 MapLayer[ ]

getLayers()
          Return this model's list of layers.

 java.lang.String

getTitle()
          Get the title, returns an empty string if it has not been set yet.

 int

indexOf(MapLayer layer)
          Returns the index of the first occurrence of the specified layer, or -1 if this list does not contain this element.

 java.util.Iterator

iterator()
          Returns an iterator over the layers in this context in proper sequence.

 void

moveLayer(int sourcePosition, int destPosition)
          Moves a layer from a position to another.

 MapLayer

removeLayer(int index)
          Remove a layer and trigger a LayerListEvent.

 boolean

removeLayer(MapLayer layer)
          Remove a layer, if present, and trigger a LayerListEvent.

 void

removeLayers(MapLayer[] layers)
          Remove an array of layers and trigger a LayerListEvent.

 void

removeMapBoundsListener(MapBoundsListener listener)
          Remove interest in receiving a BoundingBoxEvents.

 void

removeMapLayerListListener(MapLayerListListener listener)
          Remove interest in receiving LayerListEvent.

 void

removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes PropertyChangeListener from the list of listeners.

 void

setAbstract(java.lang.String conAbstract)
          Set an abstract which describes this context.

 void

setAreaOfInterest(com.vividsolutions.jts.geom.Envelope areaOfInterest)
          Set a new area of interest and trigger an BoundingBoxEvent.

 void

setAreaOfInterest(com.vividsolutions.jts.geom.Envelope areaOfInterest, org.opengis.referencing.crs.CoordinateReferenceSystem coordinateReferenceSystem)
          Set a new area of interest and trigger a BoundingBoxEvent.

 void

setContactInformation(java.lang.String contactInformation)
          Set contact inforation associated with this class.

 void

setKeywords(java.lang.String[] keywords)
          Set an array of keywords to associate with this context.

 void

setTitle(java.lang.String title)
          Set the title of this context.

 void

transform(java.awt.geom.AffineTransform transform)
          Transform the coordinates according to the provided transform.

Các hàm thường được sử dụng là

  1. Tất cả các phương thức addLayer() thêm lớp bản đồ.

  2. removeLayer(MapLayer ml) lọai bỏ một lớp bản đồ ra khỏi mapContext.

  3. removeLayers(MapLayer[] mlArray) lọai bỏ một tập hợp lớp bản đồ ra khỏi mapContext.

  4. moveLayer(int currentIndexLayer, int newIndexLayer) di chuyển vị trí các lớp bản đồ.

  5. getLayerCount() số lớp bản đồ mà MapContext chứa

  6. getLayer(int indexLayer) trả về một lớp bản đồ ở vị trí đã xác định

  7. getLayers() trả về một mảng các lớp bản đồ

  8. indexOf(MapLayer ml) trả về vị trí của lớp bản đồ trong MapContext. Lớp bản đồ trong MapContext được lưu trữ bắt đầu từ vị trí 0, nếu lớp bản đồ chưa có trong MapContext thì trả về -1.


        1. Quản lý việc hiển thị bản đồ


Sau khi tạo tích hợp các lớp bản đồ vào trong mapContext, ta bước sang giai đọan hiển thị tất cả các lớp bản đồ ra màn hình. Để làm công việc này ta tác động đến lớp StyledMapPane, lớp này giúp ta định dạng cách hiển thị bản đồ tích hợp.

StyledMapPane mapPane = new StyledMapPane();

mapPane.setMapContext(map);

mapPane.getRenderer().addLayer(new RenderedMapScale());





Hình 3.17: Công cụ hỗ trợ hiển thị bản đồ

Vì StyledMapPane thực chất là một JComponent nên muốn hiển thị ra màn hình ta cần đặt StyleMapPane vào trong JFrame hoặc Applet, JApplet.

Có 2 cách để hiển thị bản đồ:



  1. Hiển thị tại máy tính cục bộ:

Để hiển thị tại máy tính cục bộ ta có thể sử dụng chương trình Jbuilder để chạy JFrame hay Applet:

JFrame frame = new JFrame();

frame.setTitle(titleFrame);

frame.setContentPane(mapPane);

frame.setBackground(Color.white);

frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

frame.setSize(640, 480);

frame.show();



  1. Hiển thị trên nền Web:

Để hiển thị trên nền Web ta cần sử dụng đến máy ảo Java là phương tiện hỗ trợ việc hiển thị.

B1: Khai báo cách đọc dữ liệu từ các file .shp theo kiểu đọc file để đóng gói chạy trên Web giống như hướng dẫn đọc dữ liệu từ file .shp ở trên.

B2: Tạo Applet hay JApplet chứa StyledMapPane.

B3: Đóng gói trong java bằng cách vào File à New àArchive chọn Basic.

B4: Tạo file html sau đó đặt archive vào

….

archive = "MapLibs.jar"

codebase = "."

code = "frameOnWeb.FrameApplet"

name = "Show Map on the Web"

width = "800"

height = "550"

hspace = "0"

vspace = "0"

align = "middle"

>



      1. Каталог: data
        data -> HƯỚng dẫn càI ĐẶt và SỬ DỤng phần mềm tạo bài giảng e-learning
        data -> CỘng hòa xã HỘi chủ nghĩa việt nam độc lập Tự do Hạnh phúc
        data -> Qcvn 81: 2014/bgtvt
        data -> Trung taâm tin hoïC Ñhsp ñEÀ thi hoïc phaàn access
        data -> PHỤ LỤC 2 TỔng hợp danh mục tài liệu tham khảO
        data -> Công ty cổ phần Xây dựng Điện vneco3
        data -> Nghiên cứu một số đặc điểm
        data -> NHỮng đÓng góp mới của luậN Án tiến sĩ CẤP ĐẠi học huế Họ và tên ncs : Nguyễn Văn Tuấn
        data -> Mẫu 01/hc-sn-dn (Ban hành kèm theo Thông tư số 83/2007/tt-btc ngày 16/7/2007 của Bộ Tài chính) TỜ khai hiện trạng sử DỤng nhà, ĐẤt thuộc sở HỮu nhà NƯỚc và ĐỀ xuất phưƠng án xử LÝ

        tải về 5.55 Mb.

        Chia sẻ với bạn bè của bạn:
1   ...   15   16   17   18   19   20   21   22   ...   34




Cơ sở dữ liệu được bảo vệ bởi bản quyền ©hocday.com 2024
được sử dụng cho việc quản lý

    Quê hương