I'm using a MapView to display a Google Map and the trying to create a circle overlay. But for some reason the circle border is displayed but it is not filled with any color, here is what is generated using the android emulator:
Here is an idea of what I would like to achieve (i created it through the w3school online editor).
Here is the code:
LatLng center = new LatLng(-16.272425327210556,166.4380745618525);
double radius = 9944545.500957435;
CircleOptions co = new CircleOptions().center(center).clickable(false).radius((radius)).fillColor(Color.YELLOW).visible(false);
this.marker_twilight_civil = map.addCircle(co);
I tried with a different radius value and actually it works with a specific one, here i created 3 circles with different radius values, and olny one is filled, the other two are not filled.
Here is the code for the circle that is filled correctly
LatLng center = new LatLng(-16.272425356472187,166.43807456511806);
double radius = 8006044.77150472;
CircleOptions co = new CircleOptions().center(center).clickable(false).radius((radius)).fillColor(Color.GREEN).visible(true);
this.marker_night = map.addCircle(co);
Could it be a issue with the too large radius? But on the web version is working well.
It could be because the radius is too large. Google Maps uses a Mercator projection, which will skew circles if they are large enough. For technical reasons, if the shape isn't "closed" then the fill won't be applied. If the shape is too large, or too close to the highly-skewed top or bottom of the map, then the shape will break open and the fill will be ignored.
If it was truly important you could try forcing a custom Projection on Google Maps (which could avoid the skew and keep the shape closed), but this isn't a well-tread path and I can't provide a solution beyond the link:
https://developers.google.com/maps/documentation/javascript/examples/map-projection-simple
Related
I would like to change the colors of the areas of Google Maps.
Here's an example
Is there a way I could do that?
Hi you can use Polygon for draw shape.
https://developers.google.com/android/reference/com/google/android/gms/maps/model/Polygon
Another possible way is GroundOverlay.
You can overlay an image for particular area over the map (under markers, polygons, polylines).
https://developers.google.com/maps/documentation/android-api/groundoverlay
update: How to create a ground overlay layer?
For example: you want to fill this building as green.
You need to get latitude and longitude pairs for two positions : southwest and northeast.
Then create an image with transparent (such as PNG format).
After that, you need to create a ground overlay in your code.
LatLngBounds bounds = new LatLngBounds(
new LatLng(....), // South west corner
new LatLng(....) // North east corner
);
GroundOverlayOptions myBuilding = new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromResource(R.drawable.my_building))
.positionFromBounds(bounds);
You should see the target building is painted as green.
I am trying to load the 3D polygons on the map. I am able to successfully load the 3d polygon but i am not able to define the color for polygon.
Polygon3DStyleBuilder polygon3DStyleBuilder = new Polygon3DStyleBuilder();
polygon3DStyleBuilder.setColor(new Color(0xFF3333FF));
Polygon3D polygon3D = new Polygon3D(polygon3DPoses, polygon3DHoles, polygon3DStyleBuilder.buildStyle(), 150);
polygon3D.setMetaDataElement("ClickText", "3D Polygon");
vectorDataSource.add(polygon3D);
As seen in the screen the side wall is in lighter color compared to the top one. Is there a way i can define different color for side walls and the top or the same color on both side?
You may try setting the main light attributes as follows:
mapView.getOptions().setMainLight(new Color(1,1,1,1), new MapVec(0, 0, -1))
This will change the light direction to be from straight up. The top will be lighter and sides darken, but all sides will have the same color.
My design
I am writing an Android app with a Google Map component. In this app, any user can perform specific map actions in certain regions. Therefore, I want to paint the entire map in grey - except for some permitted areas defined by Polygons.
A Polygon - I would like to paint anything outside them.
Current code
The problem is that painting specific polygons is pretty straightforward with .fillColor(Color.SOME-COLOR)), so I can easily fill the polygons with color:
FeatureCollection featureCollection = (FeatureCollection)geoJSON;
List<Feature> features = featureCollection.getFeatures();
for (Feature f : features)
{
Polygon poly = (Polygon) f.getGeometry();
<...>
int c = Color.RED;
com.google.android.gms.maps.model.Polygon toAdd =
map.addPolygon(polygonOptions.strokeColor(c)
.fillColor(Color.RED));
toAdd.setGeodesic(true);
}
How do I paint everything else?
How can I do the opposite - use fillColor(Color.TRANSPARENT) and paint all the parts of the map that are not covered by a Polygon with a given color?
You can create big polygon with hole in it:
according to doc:
A polygon can be convex or concave, it may span the 180 meridian and it can have holes that are not filled in.
Link: http://developer.android.com/reference/com/google/android/gms/maps/model/Polygon.html
I'm working on Autocad files reader for android , now I Only read DXF files using Kabeja library and it works great but when i draw simple shape in Autocad and try to draw it on Android it doesn't appear
when i look to Autocad coordinates i find them are too large
I have already did a lot of search to find out any solution and one i tried is to read
EXTMIN and
EXTMAX
header values but they return {30=0.0, 20=1015.620062425179, 10=1624.318980044965} for EXTMIN
and {30=0.0, 20=2134.42060268589, 10=3716.108222970341} for EXTMAX
this is my code
DXFHeader dxfHeader = dxfDoc.getDXFHeader();
DXFVariable dxfVariableMin = dxfHeader.getVariable("$EXTMIN");
DXFVariable dxfVariableMax = dxfHeader.getVariable("$EXTMAX");
i don't know how to use these values to make my shapes be drawn correctly
EXTMIN and EXTMAX define the area of the dxf drawing that contains geometry (entities).
When displaying a dxf file, you would use the EXTMIN values as an offset.
In your example, the lower-left corner of dxf file area that contains geometry is:
1624.318980044965, 1015.620062425179
while the upper-right corner is:
3716.108222970341, 2134.42060268589
This means that your effective canvas size is actually 2091 wide by 1118 tall.
If you had an entity, like a circle, whose x,y center coordinates were 2000,1500; you could then subtract the EXTMIN coords and display the circle at 375.68, 484.38
As long as you subtract the EXTMIN coords from all your entities's x and y coords (10 and 20 group codes) you will be able to display a smaller area that just includes the area that contains geometry.
I have a MapView centered at point P. The user can't change the MapView center, but he can choose a radius of a circle to be display around point P, and change it dynamically with the map being redrawn at each change to show the new circle.
The thing is, i want the map to zoom in or out as necessary, in order to display the entire circle at the viewable area. I've tried this:
Projection proj = m_Map.getProjection();
Point mapCenterPixles = new Point();
proj.toMapPixels(center, mapCenterPixles);
float radiusPixels = proj.metersToEquatorPixels(newRadius);
IGeoPoint topLeft = proj.fromPixels(mapCenterPixles.x - radiusPixels,
mapCenterPixles.y - radiusPixels);
IGeoPoint bottomRight = proj.fromPixels(mapCenterPixles.x
+ radiusPixels, mapCenterPixles.y + radiusPixels);
m_Map.getController().zoomToSpan(
topLeft.getLatitudeE6() - bottomRight.getLatitudeE6(),
topLeft.getLongitudeE6() - bottomRight.getLongitudeE6());
But it seems i'm missing something, as the values passed to zoomToSpan() cause no chnage, I'm kind of lost here, can someone please shed some light on how to zoom the map to span a bounding box of the circle given its radius in meters, and its center points?
Google Maps zoom levels are defined in powers of two, so MapController#zoomToSpan() also zooms by powers of two.
Ergo, if the span you compute above is already displayable within the current zoom level, it's likely nothing would actually change visually in the map until you need to go to the next larger or smaller zoom level.
This behavior is somewhat vaguely described in the documentation for MapController#zoomToSpan