Flutter google maps , how to make a gradient in polylines? - google-maps

Is there any way to make the polylines a gradient, and not just the same color?
That code is working well = polylines created but i can't add gradient
//Create polylines
void _setPolylLines() {
_polylines.add(
Polyline(
polylineId: PolylineId("polylineHistoryRoute"),
points: polyLinesLatLongs,
width: 4,
patterns: <PatternItem>[PatternItem.dash(25), PatternItem.gap(15)],
color: Color.fromRGBO(86, 168, 235, 1),
),
);
}

If you are using google_maps_flutter package, it seems that the feature to add a gradient polyline is not yet available for this package as there's an existing feature request to support gradient colors to polyline/plolygons.
However, if you are using flutter_map package, perhaps you can try this.

Related

Google maps WebGL support

I have seen 3D map of Google Maps JavaScript API WebGL beta. 3D buildings visualization was so beautiful and we want to use it. I have few queries regarding this API.
-- How will be the licensing for this product when we use for commercial purpose.
-- Is their support for adding our own building data to Google cloud, so that they can be rendered using Google webGL API.
-- I have seen making buildings transparent and highlighting with some color in the example given in URL: https://geo-devrel-io2021-travel.web.app/#hotels
I wanted to change the buildings rendering such as color, transparency, and all in the same manner. I am not able to find proper documentation for implementing such, Is there any documentation for implementing such features using Google WebGL API? screenshot is shown below
enter image description here
Thanks,
Gireesh
I'm not sure the exact mechanism by which the existing building is no longer visible, but the new building with highlighting was extruded using ThreeJS.
//hotels color
const hotelMaterial = new MeshStandardMaterial({
transparent: true,
opacity: 0.5,
color: 0x00ff00
});
const roofShape = new Shape();
points.forEach((p, i) => {
i === 0 ? roofShape.moveTo(p.z, p.x) : roofShape.lineTo(p.z, p.x);
});
const extrudeSettings = {
depth: BUILDING_HEIGHT,
bevelEnabled: false
};
const roofGeometry = new ExtrudeGeometry(roofShape, extrudeSettings);
const roof = new Mesh(roofGeometry, hotelMaterial);
roof.lookAt(UP_VECTOR);
roof.rotateZ(Math.PI * 1.5);
scene.add(roof);
I'll dig a bit more into this.

How do I add Polylines to a Google Map app in Flutter?

I have a map app that I am building in Flutter and I want to add a campus map, which will be an overlay from a remote kml file eventually. In the first instances I just want to show something on the map, so I grabbed some co-ordinates form that kml file and added them to a List.
List<LatLng> building = [
LatLng(-2.2320211911239767, 53.475459515730925),
LatLng(-2.231763699058547, 53.47504046853617),
LatLng(-2.231605784002795, 53.47507219654),
LatLng(-2.2317965561189794, 53.47536812388608),
LatLng(-2.2317697340288305, 53.47537251389184),
LatLng(-2.231845506433501, 53.475498626591325),
];
I have a set of type markers and a set of type polyline
final Set<Marker> _residences = {};
final Set<Polyline> _campusOverlay = {};
I have this code in my _onMapCreated method
setState(() {
//Show Sample Building Marker
/* _residences.add(
Marker(
markerId: MarkerId('Building'),
position: _userLocation,
infoWindow: InfoWindow(
title: 'This is the title', snippet: 'This is a snippet'),
icon: BitmapDescriptor.defaultMarker,
),
);*/
_campusOverlay.add(
Polyline(
polylineId: PolylineId('Building'),
visible: true,
points: building,
width: 2,
color: Colors.red,
),
);
});
In my GoogleMap widget, I have added the markers and polylines properties.
GoogleMap(
onMapCreated: _onMapCreated,
polylines: _campusOverlay,
markers: _residences,
...
...
The marker(commented out atm) shows with no problems, but the polyline doesn't. I have seen a number of articles with this code, and I have no build errors, so I am confused as to why nothing is shown.
Am I missing something really obvious here?
[EDIT] -> Added screenshot. The co-ordinates were added to google maps (proper) and this is was is expected.
The issue wasn't with the code, but more the co-ordinates. I grabbed them from a remote KML file that I have access to. Below is an example.
-2.2346792602577352,53.46763821573774,0
I have restricted the map to my city and these co-ordinates are in the middle of the Indian ocean. These seem to be the correct way around.
53.46763821573774, -2.2346792602577352
What I can't understand is how the KML file shows the the overlay at the correct place at the moment. Not the final answer to my problem as I want to read this remote KML file and display the overlay, but for the time being, this is answered for what I wanted to do.

Google Maps and Openlayers 3 integration example

I'm using the Open Layers 3 example located at...
http://openlayers.org/en/v3.0.0/examples/google-map.html
...and I have had some success.
The problem I am running into is getting my OL3 vector and MapServer layers to be projected correctly over the web-Mercator Google Map.
I have used the example as a template but it has not worked.
Currently all MapServer and Vector layers are projected as ESPG:4326 but need to be in Web-Mercator to line up with the under lying google map.
Any help is greatly appreciated!!
You could try the OL3-Google-Maps library, one that combines the use of Google Maps API and OpenLayers together, and see if it fits your needs.
It's not a perfect solution, so be sure to read about the Limitations of the library.
The actual answer that I have implemented is here...
If this helps you please up-vote it to off-set the down-votes this received.
http://openlayers.org/en/v3.0.0/examples/google-map.html
If you need to use google imagery in you OpenLayers map this is the way to do it.
If you are using SPA MVC AngularJS architecture make sure that you make your call to the google API in your page early enough and notice that this example loads both a google div and a OpenLayers div then combines them at the end of loading...so if anything errors or stops the loading process after initialization you will see two div's the google div first and the OpenLayers div under it...once all errors are resolved and you process is able to execute ...
olMapDiv.parentNode.removeChild(olMapDiv);
gmap.controls[google.maps.ControlPosition.TOP_LEFT].push(olMapDiv);
you will see the maps combined.
If you are transforming data from EPSG:4326 to EPSG:3857 you will want to change your view projection to...
var view = new ol.View({
projection: 'EPSG:3857',
// make sure the view doesn't go beyond the 22 zoom levels of Google Maps
maxZoom: 21
});
and you will also want to transform and data points you have coming in, I did it like this...
*shape = data points from data base
var geoJsonObj = {
'type': 'Feature',
'geometry': JSON.parse(shape),
'name': 'YourName',
'id': YourName.YourID
}
var vectorSource = new ol.source.Vector({
features: (new ol.format.GeoJSON()).readFeatures(geoJsonObj, { defaultDataProjection: "EPSG:4326", featureProjection:"EPSG:3857"})
});
YourLayer = new ol.layer.Vector({
title: YourName.YourID,
source: vectorSource,
id: YourName.YourID,
name: 'YourName',
label: response.DataList[key].Label,
fill: response.DataList[key].Color,
stroke: defaultStrokeHex,
style: function (feature, resolution) {
var text = resolution * 100000 < 10 ? response.DataList[key].Label: '';
if (text != "") {
styleCache[text] = [new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#319FD3',
width: 1
}),
text: new ol.style.Text({
font: '12px Calibri,sans-serif',
text: text,
fill: new ol.style.Fill({
color: '#000'
}),
stroke: new ol.style.Stroke({
color: '#fff',
width: 3
})
}),
fill: new ol.style.Fill({
color: Utility.convertHex(response.DataList[key].Shade, '0.5')
})
})];
}
else if (text == "") {
styleCache[text] = [new ol.style.Style({
fill: new ol.style.Fill({
color: Utility.convertHex(response.DataList[key].Shade, '0.5')
})
})
]
} return styleCache[text];
}
});
There is obviously more than you need in the vector layer example above.
...an addendum to the code above
If you want the ability to turn off the satellite imagery layer below you vector data or map-server layers you can not combine the "olmap" and "gmap" div so comment those lines out and add this style to both you "gmap" and "olmap" div's
<div id="gmap" style="padding: 0px; width: 100vw; height: 90vh;z-index: 0; position:absolute"></div>
<div id="olmap" style="padding: 0px; width: 100vw; height: 90vh;z-index: 1; position:absolute"></div>
the only difference being the "z-index" and now you will have control to set the visibility on your "gmap" div dynamically...

Set colour of a Polyline in Google Maps v3?

How can I set the colour of a Google Maps Polyline?
var myRoutePath;
myRoutePath = new google.maps.Polyline({
path: routeCoordinates,
strokeColor: "#CC33FF",
strokeWeight: 3
});
myRoutePath.setMap(map);
// Reset colour
myRoutePath.setOptions({strokeColor: 'blue'});
The above doesn't show up as an error in Firebug, but it doesn't change the color either.
Thanks for your help.
Basically looks correct to me. However, if this is your code verbatim then you immediately overwrite the color. Hence, I guess you are getting a blue polyline from the start. Try setting a timer to see the transition:
setTimeout(function () {
myRoutePath.setOptions({strokeColor: 'blue'});
}, 3000);
Color names are still not supported as a color, use the hex version instead
myRoutePath.setOptions({strokeColor: '#0000FF'});

google maps adsense adunit style

I'm trying to figure out how to stylize (I really just want to change colors) the adUnit created through google maps V3. Is there no standard way to do this? most adsense ads you can stylize internally, but it is looking to me like I am stuck with the ugly blue background.
It seems like there should be a way to do this, given that you are now able to place the maps adunits outside of the map.
Thanks!
I also searched for a solution, none found. I think they don't want you to mess with the colors, it has to blend nicely with the map colors itself.
https://developers.google.com/maps/documentation/javascript/advertising?hl=en#AdUnitAdStyles
var adUnitDiv = document.createElement('div');
var adUnitOptions = {
format: google.maps.adsense.AdFormat.HALF_BANNER,
position: google.maps.ControlPosition.TOP,
backgroundColor: '#c4d4f3',
borderColor: '#e5ecf9',
titleColor: '#0000cc',
textColor: '#000000',
urlColor: '#009900',
map: map,
visible: true,
publisherId: 'YOUR_PUBLISHER_ID'
}
adUnit = new google.maps.adsense.AdUnit(adUnitDiv, adUnitOptions);
Is this what you needet?