Re: [OpenMap Users] OMLine not getting drawn

From: Tore Halset <halset_at_pvv.ntnu.no>
Date: Tue, 18 Sep 2007 21:16:52 +0200

Hello.

I have not tested your code, but wonder why you are not using
OMGraphicHandlerLayer and OMGraphicList?

Not related at all, but you will probably not want to use Vector with
generics. Generics is a sign that you are using a modern java
version, but Vector is there only for backward compatibility. You
should determine if your Collection need to handle concurrency and
read about the collection api and java.util.concurrent.

Regards,
  - Tore.

On Sep 17, 2007, at 18:24, Farhan Husain wrote:

> Hello All,
>
> I have given the code for my layer class below. The lines relevant
> to drawing OMLine are bold. As I told in a separate email to the
> group, I have another problem of not being able to catch mouse
> click problem unless I set the line type to
> OMLine.LINETYPE_GREATCIRCLE. But I want to draw it as STRAIGHTLINE.
> It would be great if anyone can explain why with straight line I
> cannot catch mouse click events.
>
> However, back to the original problem, I discovered that most of
> the lines are not being drawn by google map. I am drawing the same
> set of lines with exact same data i.e. lat & long in google map and
> it is showing all the lines in the same region where openmap is
> only showing a very few lines. All the lines are concentrating in a
> small region, to be specific, in Dallas city. I zoomed out in
> openmap thinking the lines are outside of my view but did not find
> any (and I am not supposed to).
>
> import java.util.*;
> import javax.swing.*;
> import java.awt.*;
>
> import com.bbn.openmap.layer.location.Location ;
> import com.bbn.openmap.layer.*;
> import com.bbn.openmap.omGraphics.*;
> import com.bbn.openmap.event.*;
> import com.bbn.openmap.*;
> import com.bbn.openmap.proj.*;
>
>
> public class MyLocationLayer extends Layer implements
> MapMouseListener {
> private Vector<LatLong> m_vLocationLatLong;
> private Vector<Association> m_vAssociation;
> private Vector<OMCircle> m_vOMCircle;
> private Vector<OMLine> m_vOMLine;
> private LatLonPoint m_LatLonCenter;
>
> public MyLocationLayer(Vector<LatLong> p_vLocationLatLong,
> Vector<Association> p_vAssociationForest) {
> this.setName("Location layer");
> m_vLocationLatLong = p_vLocationLatLong;
> m_vAssociation = p_vAssociationForest;
> m_LatLonCenter = null;
> makeCircles();
> makeLines();
> }
>
> public LatLonPoint getCenter() {
> return m_LatLonCenter;
> }
>
> private void makeLines() {
> if(m_vAssociation == null)
> return;
> float dLat1, dLat2, dLon1, dLon2;
> m_vOMLine = new Vector<OMLine> ();
> OMLine line;
> for(int i = 0; i < m_vAssociation.size(); i++) {
> dLat1 = Float.parseFloat(m_vAssociation.get(i).getFrom
> ().m_sLatitude);
> dLat2 = Float.parseFloat(m_vAssociation.get(i).getTo
> ().m_sLatitude);
> dLon1 = Float.parseFloat(m_vAssociation.get(i).getFrom
> ().m_sLongitude);
> dLon2 = Float.parseFloat(m_vAssociation.get(i).getTo
> ().m_sLongitude);
> line = new OMLine(dLat1, dLon1, dLat2, dLon2,
> OMLine.LINETYPE_GREATCIRCLE);
> line.addArrowHead(true);
> m_vOMLine.add(line);
> }
> }
>
> private void makeCircles() {
> m_vOMCircle = new Vector<OMCircle>();
> OMCircle cir;
> int iSkipped = 0;
> float fLat, fLon, fLatSum, fLonSum;
> fLonSum = fLatSum = 0.0f;
> for(int i = 0; i < m_vLocationLatLong.size(); i++) {
> //cir = new OMCircle(33.058211f, -96.770235f, 0.1f);
> if(m_vLocationLatLong.elementAt(i).m_sLatitude == null
> || m_vLocationLatLong.elementAt(i).m_sLongitude == null) {
> iSkipped++;
> continue;
> }
> fLat = Float.parseFloat(m_vLocationLatLong.elementAt
> (i).m_sLatitude);
> fLon = Float.parseFloat(m_vLocationLatLong.elementAt
> (i).m_sLongitude);
> cir = new OMCircle(fLat, fLon, 0.001f);
> m_vOMCircle.add(cir);
> fLatSum += fLat;
> fLonSum += fLon;
> }
> float n = (float) m_vLocationLatLong.size();
> fLatSum /= n;
> fLonSum /= n;
> m_LatLonCenter = new LatLonPoint(fLatSum, fLonSum);
> }
>
> public MapMouseListener getMapMouseListener() {
> return this;
> }
>
> public String[] getMouseModeServiceList() {
> return new String[] { SelectMouseMode.modeID };
> }
>
> public boolean mouseClicked(java.awt.event.MouseEvent e) {
> int iCount = 0;
> for(int i = 0; i < m_vOMCircle.size(); i++) {
> if(m_vOMCircle.elementAt(i).contains(e.getX (), e.getY
> ())) {
> new CrimeDetailWindow(m_vLocationLatLong.get
> (i).m_CrimeRecord, ++iCount);
> }
> }
> Vector<Association> vAssociation = new Vector<Association>();
> for(int i = 0; i < m_vOMLine.size(); i++) {
> if(m_vOMLine.get(i).contains(e.getX(), e.getY())) {
> System.out.println("You clicked line: " + i);
> vAssociation.add (m_vAssociation.get(i));
> }
> }
> return true;
> }
>
> public boolean mouseDragged(java.awt.event.MouseEvent e) {
> return true;
> }
>
> public void mouseEntered( java.awt.event.MouseEvent e) {
>
> }
>
> public void mouseExited(java.awt.event.MouseEvent e) {
>
> }
>
> public void mouseMoved() {
>
> }
>
> public boolean mouseMoved(java.awt.event.MouseEvent e) {
> return true;
> }
>
> public boolean mousePressed(java.awt.event.MouseEvent e) {
> return true;
> }
>
> public boolean mouseReleased(java.awt.event.MouseEvent e) {
> return true;
> }
>
> public void projectionChanged(ProjectionEvent pe) {
> Projection proj = setProjection(pe);
> if(null != proj) {
> try {
> for(int i = 0; i < m_vOMCircle.size(); i++)
> m_vOMCircle.elementAt(i).generate(proj);
> if(m_vOMLine != null) {
> for(int i = 0; i < m_vOMLine.size(); i++)
> m_vOMLine.elementAt(i).generate(proj);
> }
> repaint();
> } catch(Exception e) {
> System.err.println("Caught exception in
> projectionChanged " + e.getMessage());
> }
> }
> }
>
> public void paint(Graphics g) {
> float [] compArray = new float[3];
>
> if(m_vOMLine != null) {
> for(int i = 0; i < m_vOMLine.size(); i++)
> m_vOMLine.get(i).render(g);
> }
> for(int i = 0; i < m_vOMCircle.size(); i++) {
> Color cDisplayColor = m_vLocationLatLong.elementAt
> (i).m_CrimeRecord.getDisplayColor();
> cDisplayColor.getColorComponents(compArray);
> float fAlpha = ((float) m_vLocationLatLong.elementAt
> (i).m_CrimeRecord.m_iTimeIndexInQuery) /
> ((float) m_vLocationLatLong.elementAt
> (i).m_CrimeRecord.m_iTotalSameUCR);
> Color cFillColor = new Color(compArray[0], compArray
> [1], compArray[2], fAlpha);
>
> m_vOMCircle.elementAt(i).setFillPaint(Color.WHITE);
> m_vOMCircle.elementAt(i).render(g);
>
> m_vOMCircle.elementAt(i).setFillPaint(cFillColor);
> m_vOMCircle.elementAt(i).render(g);
> }
> }
> }
>
>
> --
> Mohammad Farhan Husain
> Graduate Student
> Department of Computer Science
> Erik Jonsson School of Engineering and Computer Science
> University of Texas at Dallas
>
>
> On 9/16/07, David Ward <synriga_at_yahoo.com> wrote:
> Ditto on Tore's suggestion. We need more information if you want
> the group to help.
>
> If you are seening some line but not others, check your data. Make
> sure that your coordinates for the lines are what you expect them
> to be. For example, are all the coordinates in the region you are
> viewing, do the end points have enough separation to be rendered as
> lines for the scale at which you are viewing.
>
> Cheers,
> David
>
>
>
> ----- Original Message ----
> From: Tore Halset <halset_at_pvv.ntnu.no >
> To: Farhan Husain <russoue_at_gmail.com>
> Cc: openmap-users_at_bbn.com
> Sent: Sunday, September 16, 2007 12:42:31 PM
> Subject: Re: [OpenMap Users] OMLine not getting drawn
>
> On Sep 15, 2007, at 00:31, Farhan Husain wrote:
>
> > I am trying to draw a bunch of OMLine's in my applet. In one
> > scenario, I have 135 lines. But I only find 6 lines drawn in my
> > layer. Can you please tell me where the problem is?
>
> Could you try to isolate the problem and post some code that
> reproduces the problem? I do not have any problems drawing OMLines.
>
> - Tore.
>
>
>
> --
> [To unsubscribe to this list send an email to " majdart_at_bbn.com"
> with the following text in the BODY of the message "unsubscribe
> openmap-users"]
>
>
>
>

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Tue Sep 18 2007 - 15:17:05 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:08 EDT