public void calculateVisibleElements(Envelope envelope, int zoom) { if (zoom < minZoom) { setVisibleElementsList(null); return; } if (userColumns[0] == null) return; if (renderOnce) { renderOnce = false; List<Geometry> geometries = spatialiteLayer.getVisibleElements(); if (geometries == null || geometries.size() == 0) { setVisibleElementsList(null); return; } objects = new Vector<Text>(); for (Geometry geom : geometries) { GeometryData userData = (GeometryData) geom.userData; String name = userData.label; MapPos topRight = null; if (geom instanceof Point) { topRight = ((Point) geom).getMapPos(); } else if (geom instanceof Line) { topRight = ((Line) geom).getVertexList().get(0); } else if (geom instanceof Polygon) { try { MapPos center = SpatialiteUtil.computeCentroid((Polygon) GeometryUtil.convertGeometryToWgs84(geom)); topRight = GeometryUtil.convertFromWgs84(center); } catch (Exception e) { topRight = new MapPos(0, 0); FLog.e("error computing centroid of polygon", e); } } else { FLog.e("invalid geometry type"); } Text newText = new Text(topRight, name, styleSet, null); newText.attachToLayer(this); newText.setActiveStyle(zoom); objects.add(newText); } setVisibleElementsList(objects); } }
public void loadData(Envelope envelope, int zoom) { // long time = System.currentTimeMillis(); try { ArrayList<MapPos> pts = mapView.getMapBoundaryPts(); Vector<Geometry> objectTemp = null; Vector<Geometry> objects = new Vector<Geometry>(); GeometryData.Type dataType; if (type == Type.ENTITY) { dataType = GeometryData.Type.ENTITY; objectTemp = dbmgr.fetchAllVisibleEntityGeometry( pts, querySql, renderAll ? FaimsSettings.MAX_VECTOR_OBJECTS : maxObjects); } else if (type == Type.RELATIONSHIP) { dataType = GeometryData.Type.RELATIONSHIP; objectTemp = dbmgr.fetchAllVisibleRelationshipGeometry( pts, querySql, renderAll ? FaimsSettings.MAX_VECTOR_OBJECTS : maxObjects); } else { throw new Exception("database layer has no type"); } createElementsInLayer(zoom, objectTemp, objects, dataType); setVisibleElementsList(objects); } catch (Exception e) { FLog.e("error rendering database layer", e); } if (textLayer != null) { textLayer.renderOnce(); textLayer.calculateVisibleElements(envelope, zoom); } // FLog.d("time: " + (System.currentTimeMillis() - time) / 1000); }