How can I get polyline inside available screensize?
I'm using Flutter Goolge Map Plugin , Google Map Polyline Plugin
First of all polylines added are placed wrong. you can follow my answer to generate then correctlly : https://stackoverflow.com/a/58831792/7910735
And for your Question you should use CameraUpdate.newLatLngBounds() just after placing the polylines.
Somewhat similiar to this
void animateCameraForOD() {
mapController.animateCamera(
CameraUpdate.newLatLngBounds(
LatLngBounds(
southwest: LatLng(
fromLocationLatLng.latitude <= toLocationLatLng.latitude
? fromLocationLatLng.latitude
: toLocationLatLng.latitude,
fromLocationLatLng.longitude <= toLocationLatLng.longitude
? fromLocationLatLng.longitude
: toLocationLatLng.longitude),
northeast: LatLng(
fromLocationLatLng.latitude <= toLocationLatLng.latitude
? toLocationLatLng.latitude
: fromLocationLatLng.latitude,
fromLocationLatLng.longitude <= toLocationLatLng.longitude
? toLocationLatLng.longitude
: fromLocationLatLng.longitude)),100),
);
}
It will make your both LatLngs to be zoomed out to be in the given bounds with padding also.
Related
I am trying to create a special material for a Cesium Polygon, which has to incorporate a hatched area with an outline.
Now, from the base materials I can use "Stripe", so i can create my graphic like this:
var viewer = new Cesium.Viewer('cesiumContainer');
var degrees_array = [
92.1470732697006,
21.954465553476467,
99.08781126987297,
32.557089696031916,
68.66765785924682,
24.272023818381587
];
var polygon = viewer.entities.add({
name : 'polygon',
polygon : {
hierarchy : Cesium.Cartesian3.fromDegreesArray(degrees_array),
extrudedHeight: 0,
material : new Cesium.StripeMaterialProperty(
{
evenColor:Cesium.Color.GRAY,
oddColor:Cesium.Color.WHITE,
orientation: Cesium.StripeOrientation.HORIZONTAL,
repeat:100,
offset:0
}
),
//outline is ignored by WebGL
//outline: true,
//outlineColor:Cesium.Color.BLACK,
//outlineWidth:1
}
});
//since designing an outline is not possible with polygon we create a custom polylineGraphics:
var outline_array = degrees_array;
// since loop is not available for polylineGraphics we add the first point positions
outline_array.push(outline_array[0],outline_array[1]);
var outline = viewer.entities.add({
polyline : {
positions : Cesium.Cartesian3.fromDegreesArray(outline_array),
width : 5,
material : Cesium.Color.GRAY,
clampToGround:true,
zIndex:0
}
});
viewer.zoomTo(polygon)
see sandcastle link
My questions:
- is there a way to rotate the stripes, so that they appear as diagonally hatched
- can zoom be omitted for the Stripe material, so that it is always displayed with the same line width?
Thanks a lot!
If you are still wondering. You can rotate the stripes by using stRotation
polygon: {
hierarchy: <posititons>
stRotation: Cesium.Math.toRadians(45),
material: stripeMaterial,
}
I have a map with a collection of markers on them. I need to be able to control the zIndex of the markers.
Without any zIndex code, the map works as expected, each marker is clickable (if it can be seen).
But after adding zIndex information the markers seem to gain a significant invisible wrapper and block access to nearby markers (see picture - it is now hard to click on one of the pink markers).
(I can also replicate this error with Google's example code for the plugin itself.)
Set<Marker> mkMarkers(List<Resto> restos) {
this.widget._zIndex = restos.length.toDouble();
return Set.from(
restos.asMap().map(
(int idx, Resto r) {
double hue = (r.qname == this.widget.viewModel.selectedResto)
? BitmapDescriptor.hueOrange
: 319.0;
return MapEntry(
idx,
Marker(
markerId: MarkerId(r.name),
position: LatLng(r.lat, r.lng),
onTap: () => this.widget.viewModel.onSelectResto(r.qname),
icon: BitmapDescriptor.defaultMarkerWithHue(hue),
// code below does not work as expected
zIndex: (r.qname == this.widget.viewModel.selectedResto)
? this.widget._zIndex
: idx.toDouble(),
));
},
).values,
);
}
I have a doubt, beyond looking for the code that solves my problem. Is it possible from the native cordova-plugin-googlemaps to perform this type of calculations? or should I import the javascript script from google maps? and would the google maps functions on the native google maps plugin? thank you very much
Use poly.containsLocation()
https://github.com/ionic-team/ionic-native-google-maps/tree/master/documents/poly#containslocationlocation-path
marker.on("position_changed").subscribe((params: any[]) => {
let latLng: ILatLng = params[0]; // or marker.getPosition();
let contain: boolean = Poly.containsLocation(position, POLYGON_POINTS);
marker.setIcon(contain ? "blue" : "red");
});
https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.3.0/class/utilities/geometry/poly/containsLocation/README.md
I have this code, which adds polyline primitive to scene.
function createPolyline(startPosition, endPosition) {
Cesium.SimplePolylineGeometry({
positions : [startPosition, endPosition]
});
var geometry = Cesium.SimplePolylineGeometry.createGeometry(polyline);
return scene.primitives.add(new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : geometry,
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.SPRINGGREEN)
}
}),
appearance : new Cesium.PerInstanceColorAppearance()
}));
}
How do I set width of this polyline?
The recommended way to add a polyline is with the Entity API, like this
var greenLine = viewer.entities.add({
polyline : {
positions : [startPosition, endPosition],
width : 5,
material : Cesium.Color.SPRINGGREEN
}
});
But, if you want to skip the Entity layer and use the Primitive Graphics layer directly, you can do that too. Your sample code above has some issues. First, you're calling the Cesium.SimplePolylineGeometry constructor without the new keyword, and without saving the result, and this is not the correct use pattern for this kind of code. Second, the SimplePolylineGeometry class itself does not support line widths greater than what the WebGL implementation supports, which on Windows machines running ANGLE, is only 1 pixel wide. To get around this limitation, use the normal (non-simple) polylines, like this:
var polylines = scene.primitives.add(new Cesium.PolylineCollection());
var polyline = polylines.add({
positions : Cesium.PolylinePipeline.generateCartesianArc({
positions : [startPosition, endPosition]
}),
material : Cesium.Material.fromType('Color', {
color : Cesium.Color.SPRINGGREEN
}),
width: 5
});
SimplePolylineGeometry does not support line width. You need to use PolylineGeometry instead and pass the "width" options to the constructor. Also, you should be using PolylineColorAppearance as your appearance, not PerInstanceColorAppearance.
Migrating a map to use OL3. When I call map.getView().setCenter or map.getView().zoom on the map, the map behaves correctly, but my vector data layer is no longer visible. I have to do a MouseWheelZoom interaction on the map and then the data layer shows up. This is similar to the issue found in this unanswered Stackoverflow post (How to reload WMTS Tiles after progromattically changing the map center and zoom?) except my map tiles render properly, it is my vector layer that is not visible.
I am creating the WMS tiles layer and map with this:
div = #get 'element'
layers = [ new (ol.layer.Tile)(
title: 'Imagery'
source: new (ol.source.TileWMS)(
url: WMS_VMAP_MAP_SERVER_URL
name: 'VMAP'
params:
LAYERS: 'basic'
FORMAT: 'image/png'
TRANSPARENT: true)) ]
map = new (ol.Map)(
interactions: ol.interaction.defaults().extend([ new (ol.interaction.Select)(style: selectedIconStyle) ])
controls: ol.control.defaults().extend([ new (ol.control.ScaleLine)(units: 'nautical') ])
layers: layers
target: div
view: new (ol.View)(
projection: 'EPSG:4326'
center: [
0
0
]
zoom: 1
maxResolution: 0.703125))
an individual feature is created using this:
feature = new ol.Feature({
geometry: new ol.geom.Point([lng, lat], 'XY'),
title: 'some title'
latitude: lat
longitude: lng
})
vectorSource.addFeature feature
the vector layer is add using this:
vectorLayer = new (ol.layer.Vector)(
source: vectorSource #new (ol.source.Vector)({})
style: circleIconStyle #my defined icon style
id: 'MYDATA'
)
map.addLayer vectorLayer
and when the following event fires...
map.on('singleclick', (e) ->
map.forEachFeatureAtPixel(e.pixel, ((feature, layer) ->
...
)
)
...as part of the event handler I am doing this:
map.getView().setCenter [
feature.get('longitude')
feature.get('latitude')
]
map.getView().setZoom 3
The map centers and zooms correctly, but my vector layer data does not show up by default. Is there something else I am not doing or calling in order to refresh the data layers after setCenter or zoom on the view? or is it something else I have incorrect in how I am setting this up?
thanx
Fixed. The issue was the coordinates were being treated as strings for the Geometry and not numbers. The fix is to ensure that where coordinates are being set, that they are explicitly treated as a number to remove ambiguity from the equation. So everywhere I set a lat/lon (or latitude/longitude) in the map code, I used Number(lat) and Number(lon) instead.
Props to Eric Lemoine for his answering of another issue located at http://comments.gmane.org/gmane.comp.gis.openlayers.devel.ol3/4773 as that is where I saw his solution to that marker display problem and thought it might address mine as well. And it did.