@Override public void onResume() { super.onResume(); MarkerOptions options; GoogleMap map = getMap(); map.setOnMarkerClickListener(this); map.setMyLocationEnabled(true); map.setOnInfoWindowClickListener(this); for (Mappable item : mList) { options = new MarkerOptions(); if (mDetailer != null) { mDetailer.fillMarker(item, options); } else { options .position(toLatLng(item)) .title( Double.toString(item.getMapLatitude()) + ", " + Double.toString(item.getMapLongitude())) .draggable(false); } // options.icon(BitmapDescriptorFactory.fromResource(R.drawable.map_pin_large)); map.addMarker(options); } if (mList.size() == 0) { throw new IllegalStateException("Has no point to view"); } else if (mList.size() == 1) { CameraUpdate update = CameraUpdateFactory.newLatLngZoom(toLatLng(mList.get(0)), 16); // MAGIC map.moveCamera(update); } else { map.setOnCameraChangeListener( new OnCameraChangeListener() { @Override public void onCameraChange(CameraPosition arg0) { GoogleMap map = getMap(); LatLngBounds.Builder builder = LatLngBounds.builder(); for (Mappable point : mList) { builder.include(toLatLng(point)); } CameraUpdate update = CameraUpdateFactory.newLatLngBounds(builder.build(), 20); map.moveCamera(update); map.setOnCameraChangeListener(null); } }); } }
@Override public void onInfoWindowClick(Marker marker) { if (mDetailer != null) { for (Mappable point : mList) { LatLng ll = marker.getPosition(); Location loc1 = new Location(""); loc1.setLatitude(ll.latitude); loc1.setLongitude(ll.longitude); Location loc2 = new Location(""); loc2.setLatitude(point.getMapLatitude()); loc2.setLongitude(point.getMapLongitude()); if (loc2.distanceTo(loc1) < 10) { // EPSILON mDetailer.getDetail(point); return; } } } else { // Log.i("ListMapFragment", "mDetailer is null"); } }
public synchronized double move(MappableGraph map) { boolean doitall = false; double x = 0; double y = 0; double xx = 0; double yy = 0; double r = 0; double s = 0; double t = 0; double dx = 0; double dy = 0; double d2x = 0; double d2y = 0; double d2 = 0; double d2xy = 0; Mappable a = null; Mappable b = null; CartesianPoint[] n = null; Mappable[] o = (Mappable[]) map.getShownVertices().toArray(new Mappable[0]); RadixPlaneSorter<Mappable> p = null; double delta = 0; if (alpha > Double.MIN_VALUE) { p = new RadixPlaneSorter<Mappable>(Math.sqrt(gamma), Math.sqrt(gamma), 40); for (int i = 0; i < o.length; i++) p.add(o[i]); doitall = true; } for (int i = 0; i < o.length; i++) { if (!(a = o[i]).isMobile()) continue; dx = dy = d2x = d2y = d2xy = 0; if (doitall) { n = p.getLocal(a, gamma); p.remove(a); for (int j = 0; j < n.length; j++) { b = (Mappable) n[j]; x = a.getX() - b.getX(); xx = x * x; y = a.getY() - b.getY(); yy = y * y; r = xx + yy; if (r < Double.MIN_VALUE) continue; s = r - gamma; t = 3 * gamma - r; r = 1 / Math.sqrt(r); s *= r * r * r; t *= r * r * r * r * r; /* r = Math.sqrt(r); s = (r*r -gamma) /r/r/r; t = (3*gamma - r*r)/r/r/r/r/r; */ dx += x * s; dy += y * s; d2x += s + xx * t; d2y += s + yy * t; } dx *= alpha; dy *= alpha; d2x *= alpha; d2y *= alpha; } x = y = r = 0; n = (Mappable[]) map.getShownNeighbours(a).toArray(new Mappable[0]); for (int j = 0; j < n.length; j++) { if ((b = (Mappable) n[j]) == a) continue; x += b.getX(); y += b.getY(); r += 1; } r *= 2; dx += r * a.getX() - 2 * x; dy += r * a.getY() - 2 * y; d2x += r; d2y += r; d2 = Math.abs(d2x + d2y); if (d2 > Double.MIN_VALUE) { a.setX(a.getX() - dx / d2); a.setY(a.getY() - dy / d2); delta += ((dx * dx) + (dy * dy)) / d2 / d2; } if (doitall) p.add(a); } return delta; }
public static LatLng toLatLng(Mappable mappable) { return new LatLng(mappable.getMapLatitude(), mappable.getMapLongitude()); }
public synchronized double move(MappableGraph map) { boolean doitall = false; double x = 0; double y = 0; double xx = 0; double yy = 0; double r = 0; double s = 0; double t = 0; double dx = 0; double dy = 0; double d2x = 0; double d2y = 0; double d2xy = 0; double d2 = 0; Mappable a = null; Mappable b = null; CartesianPoint[] n = null; Mappable[] o = (Mappable[]) map.getShownVertices().toArray(new Mappable[0]); RadixPlaneSorter<Mappable> p = null; double change = 0; if (gamma > Double.MIN_VALUE && alpha > Double.MIN_VALUE) { // p = new RadixPlaneSorter(Math.sqrt(gamma)/4,Math.sqrt(gamma)/4,40); p = new RadixPlaneSorter<Mappable>(Math.sqrt(gamma), Math.sqrt(gamma), 40); for (int i = 0; i < o.length; i++) p.add(o[i]); doitall = true; } for (int i = 0; i < o.length; i++) { if (!(a = o[i]).isMobile()) continue; dx = dy = d2x = d2y = 0; if (doitall) { n = p.getLocal(a, gamma); p.remove(a); for (int j = 0; j < n.length; j++) { b = (Mappable) n[j]; x = a.getX() - b.getX(); xx = x * x; y = a.getY() - b.getY(); yy = y * y; r = xx + yy; if (r < Double.MIN_VALUE) continue; // s = df(r); // t = 2*d2f(r); r = 1 / r; s = gamma * r; s = s * s; t = 4 * s * r; s = 1 - s; dx += s * x; dy += s * y; d2x += s + t * xx; d2y += s + t * yy; // d2xy += t*x*y; } dx *= alpha; dy *= alpha; d2x *= alpha; d2y *= alpha; // d2xy *= alpha; } x = y = r = 0; n = (Mappable[]) map.getShownNeighbours(a).toArray(new Mappable[0]); for (int j = 0; j < n.length; j++) { if ((b = (Mappable) n[j]) == a) continue; x += b.getX(); y += b.getY(); r += 1; } dx += r * a.getX() - x; dy += r * a.getY() - y; d2x += r; d2y += r; n = (CartesianPoint[]) map.getShownOutNeighbours(a).toArray(new Mappable[0]); s = 0; t = 0; for (int j = 0; j < n.length; j++) { if ((b = (Mappable) n[j]) == a) continue; s += a.getY() - b.getY() + delta; t += 1; } n = (CartesianPoint[]) map.getShownInNeighbours(a).toArray(new Mappable[0]); for (int j = 0; j < n.length; j++) { if ((b = (Mappable) n[j]) == a) continue; s += a.getY() - b.getY() - delta; t += 1; } dy += beta * s; d2y += beta * t; d2 = Math.abs(d2x + d2y); // d2 = Math.abs(d2x+d2y+2*d2xy); if (d2 > Double.MIN_VALUE) { a.setX(a.getX() - dx / d2); a.setY(a.getY() - dy / d2); change += ((dx * dx) + (dy * dy)) / d2 / d2; } if (doitall) p.add(a); } return change; }