I have a Map where i'm placing markers and connecting them with PolyLines:
PolylineOptions p = new PolylineOptions();
p.color(Color.BLUE);
p.width((float) 7.0);
Polyline polyLine = this.mMap.addPolyline(p);
p.add(actualLocation);
LatLng previousPoint = latLngs.get(latLngs.size() - 2);
p.add(previousPoint);
this.polyLines.add(polyLine);
mMap.addPolyline(p);
I'm saving the object p in an arraylist:
ArrayList<Polyline> polyLines = new ArrayList<>();
When i remove the last marker i want to remove the last polyline too. I'm doing the next:
if (polyLines.size() > 0) {
Polyline polyLine = polyLines.get(polyLines.size() - 1);
polyLine.remove();
polyLines.remove(polyLines.size() - 1);
}
I'm removing the marker but the polyline keeps in the Map. I'm removing it from the ArrayList too.
Can anyone help me to find out what is happening? I've tried to make the polyline invisible or changing the colour but it won't work.
It looks to me like you are in fact adding two polylines to the map... If PolylineOptions() are mutable once attached to a Polyline, they are in the same spot, otherwise you are adding one without positioning followed by a second. Only the second Polyline is being added to your List.
Instead of this:
PolylineOptions p = new PolylineOptions();
p.color(Color.BLUE);
p.width((float) 7.0);
Polyline polyLine = this.mMap.addPolyline(p); // Add before location set
p.add(actualLocation);
LatLng previousPoint = latLngs.get(latLngs.size() - 2);
p.add(previousPoint);
this.polyLines.add(polyLine);
mMap.addPolyline(p); // Add after location set
Did you want to do this?
PolylineOptions p = new PolylineOptions();
p.color(Color.BLUE);
p.width((float) 7.0);
p.add(actualLocation);
LatLng previousPoint = latLngs.get(latLngs.size() - 2);
p.add(previousPoint);
Polyline polyLine = mMap.addPolyline(p);
this.polyLines.add(polyLine);
Related
The polyline colour doesn't change even after doing this:
Polyline p;
lineOptions=new PolylineOptions();
lineOptions.addAll(points);
lineOptions.width(12);
lineOptions.geodesic(true);
lineOptions.clickable(true);
lineOptions.color(Color.BLACK);
p = mMap.addPolyline(lineOptions);
p.setColor(Color.BLUE);
My question is why?
Points is a previously declared LatLng ArrayList.
If you want to change the color of polyline which is already drawn on the map,then you need to add that polyline (of updated color) to the map, to notify that we have changed the color as below:
lineOptions.color(Color.BLACK);
p = mMap.addPolyline(lineOptions);
if(p !=null) {
p.setColor(Color.BLUE);
mMap.addPolyline(p);
}
It will change the color from black to blue
Hope this helps!
I need to add a list of geopoints as markers on top of my custom OSM map in my android device, the below code is a sample for showing up one marker.
GeoPoint startPoint = new GeoPoint(48.13, -1.63);
Marker startMarker = new Marker(map);
startMarker.setPosition(startPoint);
startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
map.getOverlays().add(startMarker);
I want to draw points there poly-lines intersects in arcgis using arcgis java apie from esri.
I have written such code which checks whether to lines intersects
Polyline polyline = new Polyline();
polyline.startPath(118.169, 34.016);
polyline.lineTo(120.941, 39.7072);
SimpleLineSymbol symbol = new SimpleLineSymbol(Color.MAGENTA, 8);
symbol.setStyle(SimpleLineSymbol.Style.SOLID);
Graphic graphic = new Graphic(polyline, symbol);
graphicsLayer.addGraphic(graphic);
Polyline polyline2 = new Polyline();
polyline2.startPath(150.169, 34.016);
polyline2.lineTo(90.941, 39.7072);
SimpleLineSymbol symbol2 = new SimpleLineSymbol(Color.BLACK, 8);
symbol2.setStyle(SimpleLineSymbol.Style.SOLID);
Graphic graphic2 = new Graphic(polyline2, symbol2);
graphicsLayer.addGraphic(graphic2);
Polyline intersection = (Polyline)GeometryEngine.intersect(polyline, polyline2, srMap);
System.out.println(intersection.getPointCount());
System.out.println(GeometryEngine.intersects(polyline, polyline2, srMap));
first print line returns 0 but the second print line returns true. How I can get thouse intersection points in arcgis?
I have a json file with coordinates and putting them in LatLng array. Some coordinates are missing because device is only sending coordinates if it's turned on. So when you turn off device and put it some where else polyline goes through whole map to another point and connect it. I need to somehow split polyline if the distance between two points gets too big. Drawing many polylines for each connecting point is not an option, because there can be 500000 points.
Can not post images here because I don't have reputation.
http://i.imgur.com/YtslNwX.png
This is how I put coordinates inside polyline options.
mapData.routeOptions here is equal to polyline options.
List<LatLng> route = new ArrayList<LatLng>();
route.addAll(positions);
double totalDistance=0;
if (route.size() > 1) {
mapData.color = suppliedMapData.color;
int color = mapData.color;
int colorAlpha = Utils.adjustAlpha(color, ROUTE_TRANSPERENCY_PERCENTAGE);
LatLngBounds.Builder boundsBuilder = LatLngBounds.builder();
for (LatLng position : route) {
boundsBuilder.include(position);
}
mapData.routeBounds = boundsBuilder.build();
mapData.routeOptions = new PolylineOptions().addAll(route).color(colorAlpha);
This is how I draw polyline.
int size = sArray.size();
for (int i = 0; i < size; i++) {
MapData mapData = sArray.valueAt(i);
if (mapData.routeOptions != null) {
mapData.routeOptions.width(7);
mPolylines.add(mMap.addPolyline(mapData.routeOptions));
hasPosData = true;
}}
Polylines are added to mPolylines array. because there are more devices than one and all off them need to be drawn.
I'm attempting to draw polygons on a map with location data as the user moves. I do not want any breaks between the polygons. I need one side of the next polygon to connect to the previous polygon's side. How would I go about this? I have what I've made so far, but I'm unsure how to gather the location data and use that from before to make the polygons connect.
I am using:
onLocationChanged(Location location) {
currentLocation = (new LatLng(location.getLatitude(), location.getLongitude()));
if(previousLocation != null) {
polygonCornerBackLeftCorner = SphericalUtil.computeOffset(currentLocation, widthInMeters / 2, location.getBearing() + 90);
polygonCornerBackRightCorner = SphericalUtil.computeOffset(currentLocation, widthInMeters / 2, location.getBearing() + 90);
}
previousLocation = currentLocation
}
polygonGenerator() {
PolygonOptions polygon = new PolygonOptions().add(polygonCornerBackLeftCorner, polygonCornerBackRightCorner, polygonCornerFrontRight, polyCornerFrontLeft).fillColor(Color.YELLOW);
getMap().addPolygon(whatsquare);
}
Whenever you get a new currentLocation, you'll want to compute the corner points that correspond to it, and you'll want to cache them for later. If this isn't the first location, then you'll have a pair of cached corner points, and you'll use them plus the new ones to make your polygon and add it to the map, and then cache the new corner points for the next iteration.