Google maps gradient polylines: need for a hack? - google-maps

I want to have a polyline that fades out from the current position (alpha = 1.0) to the start position (alpha = 0.0). In that way, give some kind of visual chronology to such a line.
After some googling, I concluded, that currently a gradient on a polyline is not part of Maps' feature set.
Am I right in this conclusion. I hope not, because I'm about to
Draw a complex polyline as many single lines, each with an increasing opacity. Question: is this going to blow up browsers, when my polyline consists of hundreds of points?
Thanks in advance..

So, here is something that is more than a comment, so I post it as an answer, realizing it might not be THE answer, and I don't expect anyone to honor this as such:
So, rather than drawing a polyline like this:
line = new google.maps.Polyline({
path: path,
map: map
});
I came up with this:
function multiMonolines (path) {
var totalPoints =path.length;
for(var i = 0; i < (path.length-1); ++i){
var startingPoint =path[i];
var endingPoint=path[i+1];
var shortPath=new Array(startingPoint,endingPoint);
line = new google.maps.Polyline({
path: shortPath,
---and here I do some stuff with opacity---
map: map
});
};
};
My finding is, that the map is drawn fast enough. (There are 381 'multimonolines').
However: zooming in on the map in Safari hangs the web page. Chrome is easier on that.
I realize that drawing 380 lines is quite an expensive thing to do, so I think I will have to revert to the polyline, hoping that someone has figured out how to do a gradient polyline. Or until Apple optimizes its js rendering engine even more.

Related

Google Map set direction in Grayscale mode

is it possible to set the direction of google Maps in grayscale(black&white) mode on the website when users select stores and want to check the direction?
I have grayscale Map on my website but when the user tries to see the direction, direction detail shows in color so is there any possible way to show that direction also in black&white?
To answer your question, yes, setting the Directions polyline colors can be changed to match your grayscale map styling.
This can be done by modifying the DirectionsRendererOptions' polylineOptions.
var directionsRenderer = new google.maps.DirectionsRenderer({
suppressMarkers: true,
polylineOptions:{
strokeColor: "#808080",
strokeWeight: 10
}
});
As you can notice, I also removed the default directions marker by setting suppressMarkers to true. That way, I can create a new marker that I could modify to match the grayscale color as well.
Please find the working sample here

Can I draw a map of the UK, split in to counties which work as hyperlinks

I have a friend who struggles organising people working around the country for the most appropriate sites in the UK (In the telecommunications sector)
I want to make him a map of the UK where each county works as a hyperlink to a list (This is because I need it to be visual and for him to understand who lives closest to each site, this could also be great, if not better as a postcode map).
I was wondering if it was possible or even if I could find the code online to draw the correct shapes for the hyperlinks, I couldn't find anything on github or any previous questions for somebody who has tried this.
As I am a beginner it would be great if I could make these hyperlinks using HTML (It doesn't need to look pretty, it just needs to be shaped like the UK!)
It would be great to get suggestions as to how I can do this.
Thanks for you time
Google Maps API is the way to go (as mentioned by other).
The idea is that you should build a polygon for each county in the UK, assign a click event to each polygon you just created and finally redirect the user to the link that you want.
I made a JSFiddle that does it for the Avon county in the UK.
https://jsfiddle.net/mpariscl/vmysg6yh/1/
$(function() {
initialize();
});
function initialize() {
var myLatlng = new google.maps.LatLng(51.6881171980821, -2.51998453948394);
var myOptions = {
zoom: 6,
center: myLatlng,
mapTypeId: 'satellite'
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var county = new google.maps.Polygon({
paths: CountyCoordinates(),
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
county.setMap(map);
google.maps.event.addListener(county, 'click', function() {
location.href = 'https://en.wikipedia.org/wiki/Avon_(county)';
});
}
You can then add the missing counties using the coordinate that you will find on this website : http://www.nearby.org.uk/counties/
Google Maps API is the way to go here. You could combine these two examples:
Geocoding for looking up the original address
KML layer For adding the location of his employees as markers so he can see who is closest.
You can generate a KML file by creating your own map on Google Maps.
It's not really beginners stuff but due to the examples you should be able to get started.
If you want an easier solution you could just create a map on Google Maps and add location of employees there. You can share maps and that would probably be a pretty good tool to solve your friends problem.
Edit I just saw your comment about Google Maps. You can perhaps make it easier by styling the map a bit and leaving out details that might be confusing. You can use something like MapStyle for that.

Google Maps V3 Polyline Drawing / Editing / Continue Drawing

I'm searching for a way to draw a polyline via google maps v3. Once complete be able to edit the polyline and then continue drawing the same polyline.
I've read much about the DrawingManager (introduced in 3.7) and read much of the API of V3 found here:
https://developers.google.com/maps/documentation/javascript/overlays#drawing_tools
Which shows the example of this:
https://google-developers.appspot.com/maps/documentation/javascript/examples/drawing-tools
The developers.google example is great and allows the user to draw and complete the polyline by clicking on the last vertex. But once it's complete I cant seem to find out how to continue drawing on the same polyline. Is this possible?
I know that Google Maps API is up to version 10 (Frozen). I've even looked in their Release and Experimental versions but there's no talk of it there.
I would be open to any suggestions.
Issue created with Google: http://code.google.com/p/gmaps-api-issues/issues/detail?id=5213
Hope it gets more "likes"
PolylineOptions in DrawingManagerOptions ignores the path atribute. So what you could do is to draw a new polyline between the end of the las polyline and the begining of the new polyline when it is drawn (on polylinecomplete event).
google.maps.event.addListener(drawingManager, 'polylinecomplete', function(event) {
if (event.type == google.maps.drawing.OverlayType.POLYLINE) {
//save last point
//draw a new polyline to join last final point and this first point if this isn't the first polyline
}
});
Hope it helps

Google maps and raising marker

I'm writing web app that uses google maps. I've got some points placed to the map as markers. When I drag the marker - it raises - and when I drop it - it falls back down. I want to avoid raising marker. Is there any way to drag it without raising?
This feature has probably been added since the question was asked but stopping the marker from raising is quite straight forward now.
When creating Marker set its 'raiseOnDrag' property to false. Like so...
marker = new google.maps.Marker ({draggable : true, raiseOnDrag : false});
Since there is no option while creating the marker I guess there is no way.
The only thing, I could imagine would be using the icons (in the reference there is an example).
But you have to try, I don't know if selfmade icons are raised or not.
You can use marker.setAnimation() method:
var marker = new google.maps.Marker({...});
google.maps.event.trigger(marker, 'dragstart'); // trigger dragstart to keep marker in the "raised" state"
marker.setAnimation(3); // raise
// later
marker.setAnimation(4); // fall
In Google Maps API there are only two types of animations documented (BOUNCE and DROP), but I have discovered two more:
1: BOUNCE,
2: DROP,
3: raise,
4: fall

Marking streets in Google Maps

I want to create an overlay on top of Google Maps that displays different streets in different colors.
In the Google Maps API it is possible to create markers and polygons that cover certain areas.
Is there a way to somehow mark different streets?
It sounds to me like you are interested in showing some application specific coloring for your Google maps display (rather than traffic maps).
If so , then you should check out custom overlays. You can create your own transparent background overlay tiles (with your colored streets), match them up with the Google maps tiles and then overlay them on the map. You can find a description of this stuff in the Maps API reference - Overlays.
I have actually been interested in trying this out, and this question might be a good excuse. I'll let you know how I go.
Edit: Ok, I tried this and it was pretty straightforward. You just need to grab the tiles images when the google maps page load (for the area you would like to overlay). Make sure you keep track of the origional urls, because these have the x,y coordinates that you will need to write your tile overlay method.
Edit the tiles with your colored roads then upload them to your web server. Add the following code to use your overlay on the regular map:
var myCopyright = new GCopyrightCollection("© ");
myCopyright.addCopyright(new GCopyright('Demo',
new GLatLngBounds(new GLatLng(-90,-180), new GLatLng(90,180)),
0,'©2007 Google'));
// Create the tile layer overlay and
// implement the three abstract methods
var tilelayer = new GTileLayer(myCopyright);
// properties of the tile I based my tile on
// v=w2.97&hl=en&x=38598&s=&y=49259&z=17&s=Galil.png
tilelayer.getTileUrl = function(point, zoom) {
if (zoom == 17 && point.x == 38598 && point.y == 49259)
return "../pics/times_square.png";
};
tilelayer.isPng = function() { return true;};
tilelayer.getOpacity = function() { return 1.0; }
var myTileLayer = new GTileLayerOverlay(tilelayer);
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(40.75740, -73.98590), 17);
map.addOverlay(myTileLayer)
This code overlays my Thing eats NY tile:
at x = 38598 and y = 49259 at zoom level 17.
It is possible to create markers and polygons in the Google Maps API. You need to create GPolygon and/or GPolyline objects
Have a look to these tutorials
And if you want to obtain the coordinate (latitude, longitude) of certain streets, you may have a look to the source code of this page
I am not sure to fully understand your question: do you want to mark some given streets ?
in that case, a quick-and-dirty way could be to get the coordinates of all the addresses of the street and build a GPolygon according to them...
Have you concidered using OpenStreeMaps?
Try digging into the code used to show the traffic overlay on the normal Google Maps site.
Edit: I just looked at the code, and it appears that even Google decided it was easier to implement this by just generating the traffic lines on the server and pulling them down as transparent PNG overlays.
I just found this link, and I think this could interest you. It is a JavaScript package that provides functionality for displaying multiple routes on Google Maps.
Is it what you were looking for ??