putting only symbolpath icon in current position - google-maps-api-3

I am trying to put symbol path icon on the current position of the route,but the icon did not show on the map.
var carPath = new google.maps.MVCArray();
for ( var i = 0; i < path_start.length; i++) {
if(i === 0) {
carPath.push(path_start[i]);
carPolyline.setPath(carPath);
} else {
setTimeout((function(latLng) {
return function() {
new google.maps.Marker({
map: map,
icon:{
path:google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale:3,
strokeColor: 'white',
strokeWeight: 1,
fillOpacity: 0.8,
fillColor: 'orange',
offset: '100%'
},
position: path_start[i],
});
carPath.push(latLng);
};
})(path_start[i]), 100 * i);
}
}
Thank you in advance.
http://jsfiddle.net/jemz24/kSKGs/3/

The name of the variable that holds the google.maps.LatLng object you need inside the anonymous function is latLng, not path_start[i]
working fiddle
Change:
new google.maps.Marker({
map: map,
icon:{
path:google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale:3,
strokeColor: 'white',
strokeWeight: 1,
fillOpacity: 0.8,
fillColor: 'orange',
offset: '100%'
},
position: path_start[i]
});
to:
new google.maps.Marker({
map: map,
icon:{
path:google.maps.SymbolPath.FORWARD_CLOSED_ARROW,
scale:3,
strokeColor: 'white',
strokeWeight: 1,
fillOpacity: 0.8,
fillColor: 'orange',
offset: '100%'
},
position: latLng
});
More likely what you want updated fiddle
Add the icon to the polyline, don't make it a marker.
var lineSymbol = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
};
var carPolyline = new google.maps.Polyline({
map: map,
geodesic : true,
strokeColor : '#FF0000',
strokeOpacity : 1.0,
strokeWeight : 2,
icons: [{
icon: lineSymbol,
offset: '100%'
}],
});

Related

How can I make multi line label on google maps when using chrome?

I’m making a system which shows the marker with text(status,price,owner of apartments).
I haved tested it on IE using label text.
It used to work fine with /n to break a line.
But when I changed to chrome browser, label text’s /n doesnt’ work at all.... I want this label text to be multi line.
Is there anyone who have an idea?
I want to print label with 3 lines aaaaaaa bbbb cccc
But this doesn’t work:
var marker2 = new google.maps.Marker({
title:"A\nBa",
position: {
lat: 12.975688,
lng: 77.640812
},
label: {
text:"aaaaaaa \n bbbb \n cccc"
},
icon: {
path: google.maps.SymbolPath.CIRCLE,
fillColor: "green",
strokeColor: "green",
fillOpacity: 1.0,
scale: 20
},
map: map
});
One option would be to use the third party MarkerWithLabel utility library. That supports HTML tags in its labelContent field (and CSS styling of the labelContent)
var marker = new MarkerWithLabel({
position: bangalore,
labelContent: "A<br/>B",
labelAnchor: new google.maps.Point(2, 12),
icon: {
path: google.maps.SymbolPath.CIRCLE,
fillColor: "red",
strokeColor: "red",
fillOpacity: 1.0,
scale: 20
},
map: map
});
proof of concept fiddle
code snippet:
function initialize() {
var bangalore = {
lat: 12.97,
lng: 77.59
};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: bangalore
});
var marker = new MarkerWithLabel({
position: bangalore,
labelContent: "aaaaaaa <br/> bbbb <br/> cccc",
labelAnchor: new google.maps.Point(20, 20),
labelStyle: {
textAlign: "center"
},
icon: {
path: google.maps.SymbolPath.CIRCLE,
fillColor: "red",
strokeColor: "red",
fillOpacity: 1.0,
scale: 20
},
map: map
})
}
google.maps.event.addDomListener(window, 'load', initialize);
html,
body,
#map {
height: 100%;
margin: 0;
padding: 0;
}
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<script src="https://cdn.jsdelivr.net/gh/geocodezip/v3-utility-library/packages/markerwithlabel/src/markerwithlabel.js"></script>

Is it possible to have the editable attribute turned off in a polyline but still display the vertices as clickable circles?

I would like to display a polyline so that the vertices can not be moved, deleted or added, ie exactly like when the editable attribute is set to false, but the circles which are present when the editable attribute is set to true are still visible so that they can be clicked and a vertex number obtained.
So the polyline code could be:
newPoly = new google.maps.Polyline({
strokeColor: '#08088a',
strokeWeight: 2,
editable: false
});
Is this possible?
One option: process through the polyline, add circular markers to each vertex in the line with the vertex number in the marker's infowindow.
Related question: Google Maps V3 Polyline : make it editable without center point(s)
proof of concept fiddle
code snippet:
function initialize() {
var infowindow = new google.maps.InfoWindow();
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(37.4419, -122.1419),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var polyCoord = [
new google.maps.LatLng(41.86, 8.73),
new google.maps.LatLng(41.88, 8.75),
new google.maps.LatLng(42, 8),
new google.maps.LatLng(43.5, 9)
];
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < polyCoord.length; i++) {
bounds.extend(polyCoord[i]);
var marker = new google.maps.Marker({
position: polyCoord[i],
title: '#0',
map: map,
icon: {
path: google.maps.SymbolPath.CIRCLE,
fillColor: 'white',
fillOpacity: 1,
scale: 3,
strokeColor: 'black',
strokeWeight: 1,
strokeOpacity: 1,
// anchor: new google.maps.Point(200, 200)
}
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent("vertex #" + i + "<br>coord: (" + this.getPosition().toUrlValue(6) + ")");
infowindow.open(map, marker);
}
})(marker, i));
}
map.fitBounds(bounds);
// Polyline
var newPoly = new google.maps.Polyline({
strokeColor: '#08088a',
strokeWeight: 2,
editable: false,
path: polyCoord,
map: map
});
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas" style="border: 2px solid #3872ac;"></div>

fusiontable infowindow style on googlemaps api

I have a map with googlemaps api.
I've added a polygon FusionTable layer.
When I click on a polygon, it shows me the default infowindow with .googft-info-window class.
I want to make changes to that class, or assign other class to these infowindows.
There's a way to do so?
That's my code.
function initialize() {
var mapDiv = document.getElementById('lugar-do-mapa');
map = new google.maps.Map(mapDiv, {
center: new google.maps.LatLng(-12.726084,-51.855469),
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
}
});
fusion = new google.maps.FusionTablesLayer({
query: {
select: 'geometry',
from: 'xxxxXXXxxx'
},
styles: [{
polygonOptions: {
fillColor: "#FFFFFF",
fillOpacity: 0.1,
strokeColor: "#ff4d4d",
strokeWeight: "int"
}
}]
});
fusion.setMap(map);
}
Thank you all,
It works like Dr. Molle said, just placed the class .googft-info-window on my css and changed the parameters...thanks.

Is there a way to make overlay objects non-clickable?

I'm working on this project of mine that requires to define lat/lng elements by clicking and finally found a way to do so, but just discovered, that the already predefined elements interfere with the new overlay elements defining by the source below. So I looked and looked, and searched, and googled, but wasn't able to find any helpful info about that: is there a way to make the google maps overlays non-clickable?
I'm using a custom function to get the latitude and longitude of a click event and place a predefined circle overlay object. However if I have already predefined overlay elements, I cannot click on top of them to set a new overlay element. I.e. I'd need either to make them non-interactable or non-clickable, or just to set them on a different layer, so that they don't interfere with the click events for the new elements.
Here's the JS I use:
<script type="text/javascript">
var map;
var markersArray = []; //the array for the newly defined objects
function initMap()
{
var latlng = new google.maps.LatLng(41, 29);
var myOptions = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
// add a click event handler to the map object
google.maps.event.addListener(map, "click", function(event)
{
// place a marker
placeMarker(event.latLng);
});
// I've predefined a couple of markers just to see how it works with already defined elements and discovered this interference that I mentioned above
var mar1 = new google.maps.LatLng(40.9653, 29.3705);
var marker1 = new google.maps.Circle({
center: mar1,
radius: 2500,
fillColor: "#FF0000",
strokeWeight: 0,
fillOpacity: 0.35,
map: map
});
var mar2 = new google.maps.LatLng(40.9664, 29.3252);
var marker2 = new google.maps.Circle({
center: mar2,
radius: 2500,
fillColor: "#FF0000",
strokeWeight: 0,
fillOpacity: 0.35,
map: map
});
marker1.setMap(map);
marker2.setMap(map);
}
function placeMarker(location) {
// first remove all new markers if there are any, so that we define one new at a time
deleteOverlays();
var new_marker = new google.maps.Circle({
center: location,
radius: 2500,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 0,
fillColor: "#FF0000",
fillOpacity: 0.35,
//position: location,
map: map
});
// add marker in markers array
markersArray.push(new_marker);
}
// Deletes all markers in the array by removing references to them
function deleteOverlays() {
if (markersArray) {
for (i in markersArray) {
markersArray[i].setMap(null);
}
markersArray.length = 0;
}
}
</script>
fiddle
set {clickable: false} in the CircleOptions.
var new_marker = new google.maps.Circle({
center: location,
radius: 2500,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 0,
fillColor: "#FF0000",
fillOpacity: 0.35,
clickable: false, // <=====================
map: map
});
Modified jsfiddle

How to iterate a list with itemtap (sencha touch 2)

I would like to know how to use itemtap to iterate through a list. I have a list right now which shows multiple items and when the user clicks on each, a map will appear showing the marker of the item. However, every item on the list seems to be showing the same thing. It is just showing the latest item on the list (first at the top). I would like to know what I'm doing wrong with the itemtap function. Thank You!!
Heres my controller where the itemtap function is:
Ext.define('demo.controller.News',{
extend:'Ext.app.Controller',
config:{
refs:{
NewsContainer:'newscontainer'
},
control:{
'newscontainer new list':{
itemtap:function(list, index, target, record){
var detailsView = Ext.create('demo.view.Mapo');
detailsView.setData(record.data);
this.getNewsContainer().push(detailsView);
}
}
}
}
});
And here is my map:
Ext.define('demo.view.Mapo', {
extend: 'Ext.Map',
xtype:'mapo',
config: {
title:'Incident Location',
iconCls:'maps',
layout:'fit',
draggable: true,
useCurrentLocation: true,
mapOptions: {
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
},
initialize: function(){
var me = this;
me.on('maprender', function(comp, map){
var image = 'resources/images/current.png';
new google.maps.Marker({
position: new google.maps.LatLng(
this._geo.getLatitude(),
this._geo.getLongitude()
),
icon: image,
map: map,
title: "Current Location",
animation: google.maps.Animation.DROP
});
//Circle Radius
// var populationOptions = {
// strokeColor: "#FF0000",
// strokeOpacity: 0.8,
// strokeWeight: 1,
// fillColor: "#FF0000",
// fillOpacity: 0.35,
// map: map,
// center: new google.maps.LatLng(this._geo.getLatitude(),
// this._geo.getLongitude()),
// radius: 2000
// };
// var t = new google.maps.Circle(populationOptions);
for (i=0; i<Ext.getStore('news').getData().length; i++){
var data = Ext.getStore('news').getData().items[i].data
};
new google.maps.Marker({
position: new google.maps.LatLng(
data.Latitude,
data.Longitude
),
// icon: image,
map: map,
title: "Incident Location",
animation: google.maps.Animation.BOUNCE
});
});
me.callParent(arguments);
}
});

Resources