I want to display infobox outside the googlemap after hover div out the map. In this code mastercluster and infobox working properly but problem in to display only outside div.
var pop = document.getElementById('example1');
var locations = <?php echo json_encode($jsArray); ?>;
var image = 'images/mapmarker.png';
var myLatlng = new google.maps.LatLng(locations[0][0], locations[0][1]);
var myOptions = {
zoom: 10,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDoubleClickZoom: false,
disableDefaultUI: true,
visibleInfoWindow: null,
zoomControlOptions: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE
}
};
var mcOptions = {styles: [{
opt_textColor: 'white',
textColor: 'white',
height:34,
url: image,
width:34
}],
description: ' tracks: click to show'
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
var markers = [];
for(var i=0;i<locations.length;i++)
{
var latlng=new google.maps.LatLng(locations[i][0], locations[i][1]);
var marker = new google.maps.Marker({
position: latlng,
map: map,
icon: image
});
boxText = document.createElement("div");
infoboxOptions = {
content: boxText,
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(18, -60),
zIndex: null,
boxStyle: {
opacity: 0.75,
width: "250px"
},
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
};
markers.push(marker);
boxText.style.cssText = "border: 1px solid black; margin-top:3px; background:#333; color:#FFF; font-family:Arial; font-size:12px; padding: 3px; border-radius:6px; -webkit-border-radius:6px; -moz-border-radius:6px;";
boxText.innerHTML = "<b>Hotel Name</b>: "+locations[i][2] + "<br/><br/>" + "<b>Rating</b>: "+locations[i][3]+"<br/><br/>"+"<b>Price:</b> € "+locations[i][4];
markers[i].infobox = new InfoBox(infoboxOptions);
pop.onmouseout = generateTriggerCallback(marker[i], 'mouseout');
pop.onmouseover = generateTriggerCallback(marker[i], 'mouseover');
$(".popup_slide").hover(function(){
$(this).addClass("resulthover");
},
function () {
$(this).removeClass("resulthover");
});
google.maps.event.addListener(marker, 'mouseover', (function(marker, i) {
return function() {
markers[i].infobox.open(map, this);
}
})(marker, i));
google.maps.event.addListener(marker, 'mouseout', (function(marker, i) {
return function() {
markers[i].infobox.close(map, this);
}
})(marker, i));
}
var markerCluster = new MarkerClusterer(map, markers, mcOptions);
function generateTriggerCallback(object, eventType) {
return function() {
google.maps.event.trigger(object, eventType);
};
}
Finally i got solution and my problem is solved. My Problem was i have a set on location and we have to show that locations on the google map and at same time it will show as result outside of map. The enhanced functionality is on hover outside of the result map location will show on the google map.
var locations = <?php echo json_encode($jsArray); ?>;
var foo2 = document.getElementById('foo2');
var generateLink = document.getElementById('generateLink');
var image = 'images/mapmarker.png';
var image_hover = 'images/mapmarker_hover.png';
var img29 = 'images/29cluster.png';
var img34 = 'images/34cluster.png';
var img47 = 'images/47cluster.png';
var img56 = 'images/56cluster.png';
var clusterStyles = [
{
opt_textColor: 'white',
textColor: 'white',
url: img29,
height: 29,
width: 29
},
{
opt_textColor: 'white',
textColor: 'white',
url: img34,
height: 34,
width: 34
},
{
opt_textColor: 'white',
textColor: 'white',
url: img47,
height: 47,
width: 47
},
{
opt_textColor: 'white',
textColor: 'white',
url: img56,
height: 56,
width: 56
}
];
var visibleInfoWindow = null;
var myLatlng = new google.maps.LatLng(locations[0][0], locations[0][1]);
var myOptions = {
zoom: 8,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDoubleClickZoom: false,
disableDefaultUI: true,
visibleInfoWindow: null,
zoomControlOptions: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE
}
};
var mcOptions = { styles: clusterStyles,
zoomOnClick: true
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
var markers = [];
function generateTriggerCallback(object, eventType) {
return function() {
google.maps.event.trigger(object, eventType);
};
}
function clearMarkers() {
for (var n = 0, marker; marker =markers[n]; n++) {
marker.setVisible(false);
}
}
var div = foo2;
clearMarkers();
var example = [];
for(var i=0;i<locations.length;i++)
{
var latlng=new google.maps.LatLng(locations[i][0], locations[i][1]);
var marker = new google.maps.Marker({
position: latlng,
map: map,
icon: image
});
boxText = document.createElement("div");
infoboxOptions = {
content: boxText,
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(16, -40),
zIndex: null,
boxStyle: {
opacity: 0.75,
width: "250px"
},
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
};
markers.push(marker);
var rate = locations[i][3];
if(rate == 1)
{
var rateimg = "<img src='images/rating.png' alt=''/><img src='images/unactiverating.png' alt=''/><img src='images/unactiverating.png' alt=''/><img src='images/unactiverating.png' alt=''/><img src='images/unactiverating.png' alt=''/>";
}else if(rate == 2)
{
var rateimg = "<img src='images/rating.png' alt=''/><img src='images/rating.png' alt=''/><img src='images/unactiverating.png' alt=''/><img src='images/unactiverating.png' alt=''/><img src='images/unactiverating.png' alt=''/>";
}
else if(rate == 3)
{
var rateimg = "<img src='images/rating.png' alt=''/><img src='images/rating.png' alt=''/><img src='images/rating.png' alt=''/><img src='images/unactiverating.png' alt=''/><img src='images/unactiverating.png' alt=''/>";
}else if(rate == 4)
{
var rateimg = "<img src='images/rating.png' alt=''/><img src='images/rating.png' alt=''/><img src='images/rating.png' alt=''/><img src='images/rating.png' alt=''/><img src='images/unactiverating.png' alt=''/>";
}
else if(rate == 5)
{
var rateimg = "<img src='images/rating.png' alt=''/><img src='images/rating.png' alt=''/><img src='images/rating.png' alt=''/><img src='images/rating.png' alt=''/><img src='images/rating.png' alt=''/>";
}
//define the text and style for all infoboxes
boxText.style.cssText = "border: 1px solid black;background:#333; padding:3px;color:#FFF; font-family:Arial; font-size:12px; border-radius:6px; -webkit-border-radius:6px; -moz-border-radius:6px;";
boxText.innerHTML = "<div class='marker11'> </div><b>Hotel Name</b>: "+locations[i][2] + "<br/>" + "<b>Rating</b>: "+rateimg+"<br/>"+"<b>Price:</b> € "+locations[i][4];
//Define the infobox
markers[i].infobox = new InfoBox(infoboxOptions);
$(".popup_slide").hover(function(){
$(this).addClass("resulthover");
},
function () {
$(this).removeClass("resulthover");
});
google.maps.event.addListener(marker, 'mouseover', (function(marker, i) {
return function() {
markers[i].infobox.open(map, this);
marker.setIcon(image_hover);
}
})(marker, i));
google.maps.event.addListener(marker, 'mouseout', (function(marker, i) {
return function() {
markers[i].infobox.close(map, this);
marker.setIcon(image);
}
})(marker, i));
example[i] = document.getElementById('example' + i);
example[i].onmouseover = generateTriggerCallback(marker, 'mouseover');
example[i].onmouseout = generateTriggerCallback(marker, 'mouseout');
}//end of for loop
var markerCluster = new MarkerClusterer(map, markers, mcOptions);
//globalMarker = markers.slice();
google.maps.event.addListener(markerCluster, "mouseover", function (c) {
var totalcluster = c.getSize();
var centercluster = c.getCenter();
var m = c.getMarkers();
var p = [];
for (var j = 0; j < m.length; j++ ){
p.push(m[j].getPosition());
}
//alert(p);
});
google.maps.event.addListener(markerCluster, "mouseout", function (c) {
});
Related
I'm using google maps API to allow the user draw polygons and display the length of every single border using maplabel library. But I have a problem when removing polygon and map label, I don't know how to remove them from Google Map.
My code looks like this:
HTML
<button id="enablePolygon">draw</button>
<button id="removePolygon">remove</button>
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&libraries=drawing"></script>
<script src="https://cdn.jsdelivr.net/npm/js-map-label#1.0.1/src/maplabel.js"></script>
JS
var labels = [];
var allOverlays = [];
function setSelection(shape) {
selectedShape = shape;
shape.setEditable(true);
}
function initMap() {
var options = {
zoom: 14,
center: {
lat: 52.250618,
lng: 20.9774
}
};
var map = new google.maps.Map(document.getElementById("map"), options);
var drawingManager = new google.maps.drawing.DrawingManager({
polygonOptions: {
draggable: false,
fillColor: "#0e97fa",
fillOpacity: 0.2,
strokeWeight: 2,
strokeColor: "#0e97fa",
editable: true,
zIndex: 1
},
drawingControl: false,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes:
[
google.maps.drawing.OverlayType.POLYGON,
/* google.maps.drawing.OverlayType.POLYLINE, */
]
},
map: map,
drawingMode: 'polygon'
});
function attachPolygonInfoWindow(polygon) {
if (!polygon.labels) polygon.labels = [];
for (var i = 0; i < polygon.labels.length; i++) {
polygon.labels[i].setMap(null);
}
polygon.labels = [];
var path = polygon.getPath();
var points = path.getArray();
var area = google.maps.geometry.spherical
.computeArea(path.getArray())
.toFixed(0);
var bounds = new google.maps.LatLngBounds();
var i;
for (i = 0; i < points.length; i++) {
bounds.extend(points[i]);
}
var boundsCenter = bounds.getCenter();
var centerLabel = new MapLabel({
map: map,
position: boundsCenter,
fontSize: 14,
align: "center",
zIndex: 3
});
polygon.labels.push(centerLabel);
centerLabel.set("position", bounds.getCenter());
centerLabel.set("text", area + " m2");
if (path.getLength() < 2) return;
for (var i = 0; i < polygon.getPath().getLength(); i++) {
// for each side in path, compute center and length
var start = polygon.getPath().getAt(i);
var end = polygon.getPath().getAt(i < polygon.getPath().getLength() - 1 ? i + 1 : 0);
var sideLength = google.maps.geometry.spherical.computeDistanceBetween(start, end);
console.log(sideLength)
var sideCenter = google.maps.geometry.spherical.interpolate(start, end, 0.5);
/* console.log("sideCenter=" + sideCenter.toUrlValue(6)); */
var sideLabel = new MapLabel({
map: map,
fontSize: 14,
align: "center",
zIndex: 3
});
sideLabel.set("position", sideCenter);
sideLabel.set("text", sideLength.toFixed(2) + "m");
polygon.labels.push(sideLabel);
}
}
function removePolygonInfoWindow() {
for (var i = 0; i < labels.length; i++) {
labels[i].setMap(null);
}
labels = [];
}
google.maps.event.addListener(drawingManager, "overlaycomplete", function(e) {
allOverlays.push(e);
if (e.type != google.maps.drawing.OverlayType.MARKER) {
drawingManager.setDrawingMode(null);
var newShape = e.overlay;
newShape.type = e.type;
google.maps.event.addListener(newShape, "click", function() {
setSelection(newShape);
});
if (newShape.type == "polygon") {
var path = newShape.getPath();
google.maps.event.addListener(path, "insert_at", function() {
attachPolygonInfoWindow(newShape);
});
google.maps.event.addListener(path, "set_at", function() {
attachPolygonInfoWindow(newShape);
});
attachPolygonInfoWindow(newShape);
}
setSelection(newShape);
}
});
var enablePolygon = document.getElementById('enablePolygon');
enablePolygon.addEventListener('click', function(){
drawingManager.setMap(map);
drawingManager.setDrawingMode(google.maps.drawing.OverlayType.POLYGON);
});
var removePolygon = document.getElementById('removePolygon');
removePolygon.addEventListener('click', function(){
selectedShape.setMap(null);
drawingManager.setMap(null);
centerLabel.setRemoveLabel(true);
});
}
initMap();
Here is demo
I get a javascript error with the posted code: Uncaught ReferenceError: centerLabel is not defined. Not sure why you are using that variable, you are saving the labels in a property of the polygons labels. To remove them, iterate through that array, calling .setMap(null) on each label.
removePolygon.addEventListener('click', function() {
selectedShape.setMap(null);
drawingManager.setMap(null);
for (var i = 0; i < selectedShape.labels.length; i++) {
selectedShape.labels[i].setMap(null);
}
});
updated fiddle
code snippet:
var labels = [];
var allOverlays = [];
function setSelection(shape) {
selectedShape = shape;
shape.setEditable(true);
}
function initMap() {
var options = {
zoom: 14,
center: {
lat: 52.250618,
lng: 20.9774
}
};
var map = new google.maps.Map(document.getElementById("map"), options);
var drawingManager = new google.maps.drawing.DrawingManager({
polygonOptions: {
draggable: false,
fillColor: "#0e97fa",
fillOpacity: 0.2,
strokeWeight: 2,
strokeColor: "#0e97fa",
editable: true,
zIndex: 1
},
drawingControl: false,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [
google.maps.drawing.OverlayType.POLYGON,
/* google.maps.drawing.OverlayType.POLYLINE, */
]
},
map: map,
drawingMode: 'polygon'
});
function attachPolygonInfoWindow(polygon) {
if (!polygon.labels) polygon.labels = [];
for (var i = 0; i < polygon.labels.length; i++) {
polygon.labels[i].setMap(null);
}
polygon.labels = [];
var path = polygon.getPath();
var points = path.getArray();
var area = google.maps.geometry.spherical
.computeArea(path.getArray())
.toFixed(0);
var bounds = new google.maps.LatLngBounds();
var i;
for (i = 0; i < points.length; i++) {
bounds.extend(points[i]);
}
var boundsCenter = bounds.getCenter();
var centerLabel = new MapLabel({
map: map,
position: boundsCenter,
fontSize: 14,
align: "center",
zIndex: 3
});
polygon.labels.push(centerLabel);
centerLabel.set("position", bounds.getCenter());
centerLabel.set("text", area + " m2");
if (path.getLength() < 2) return;
for (var i = 0; i < polygon.getPath().getLength(); i++) {
// for each side in path, compute center and length
var start = polygon.getPath().getAt(i);
var end = polygon.getPath().getAt(i < polygon.getPath().getLength() - 1 ? i + 1 : 0);
var sideLength = google.maps.geometry.spherical.computeDistanceBetween(start, end);
console.log(sideLength)
var sideCenter = google.maps.geometry.spherical.interpolate(start, end, 0.5);
/* console.log("sideCenter=" + sideCenter.toUrlValue(6)); */
var sideLabel = new MapLabel({
map: map,
fontSize: 14,
align: "center",
zIndex: 3
});
sideLabel.set("position", sideCenter);
sideLabel.set("text", sideLength.toFixed(2) + "m");
polygon.labels.push(sideLabel);
}
}
function removePolygonInfoWindow() {
for (var i = 0; i < labels.length; i++) {
labels[i].setMap(null);
}
labels = [];
}
google.maps.event.addListener(drawingManager, "overlaycomplete", function(e) {
allOverlays.push(e);
if (e.type != google.maps.drawing.OverlayType.MARKER) {
drawingManager.setDrawingMode(null);
var newShape = e.overlay;
newShape.type = e.type;
google.maps.event.addListener(newShape, "click", function() {
setSelection(newShape);
});
if (newShape.type == "polygon") {
var path = newShape.getPath();
google.maps.event.addListener(path, "insert_at", function() {
attachPolygonInfoWindow(newShape);
});
google.maps.event.addListener(path, "set_at", function() {
attachPolygonInfoWindow(newShape);
});
attachPolygonInfoWindow(newShape);
}
setSelection(newShape);
}
});
var enablePolygon = document.getElementById('enablePolygon');
enablePolygon.addEventListener('click', function() {
drawingManager.setMap(map);
drawingManager.setDrawingMode(google.maps.drawing.OverlayType.POLYGON);
});
var removePolygon = document.getElementById('resetPolygon');
removePolygon.addEventListener('click', function() {
selectedShape.setMap(null);
drawingManager.setMap(null);
for (var i = 0; i < selectedShape.labels.length; i++) {
selectedShape.labels[i].setMap(null);
}
});
}
initMap();
html,
body,
#map {
height: 100%;
margin: 0;
padding: 0;
}
<button id="enablePolygon">draw</button>
<button id="resetPolygon">remove</button>
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&libraries=drawing"></script>
<script src="https://cdn.jsdelivr.net/npm/js-map-label#1.0.1/src/maplabel.js"></script>
I am trying to draw an airline flight map using Google Map APIs. But I got some issues in generating polylines between every two points. So far, it only returns one polyline of the very first two points. I could not find any error so far. Is there anything wrong with the last for loop? Any comments and help will be highly appreciated!
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 5,
center: {lat: 41.871314, lng: -99.869580},
mapTypeId: google.maps.MapTypeId.TERRAIN
});
var Lat = [42.365843,37.756066,47.450431,28.431450,38.898793,34.040667];
var Lng = [-71.009625,-122.440175,-122.308806,-81.308094,-77.037227,-118.289537];
var lineSymbol = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
};
var Poly = new Array();
for (var i = 0; i<Lat.length; i++) {
var pos = new google.maps.LatLng(Lat[i],Lng[i]);
Poly.push(pos);
};
for (var j = 0; j<Poly.length; j++) {
if (j%2 == 0){
var poly = new Array();
poly = Poly.slice(j,j+2);
var flowline = new google.maps.Polyline({
path: poly,
geodesic: true,
strokeColor: "#DC143C",
strokeOpacity: .8,
strokeWeight: 2,
icons: [{
icon: lineSymbol,
offset: '100%'
}],
});
}
};
flowline.setMap(map);
}
You are only setting the map property of the last polyline. This is outside of the loop that creates the polylines:
flowline.setMap(map);
proof of concept fiddle
code snippet:
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: {
lat: 41.871314,
lng: -99.869580
},
mapTypeId: google.maps.MapTypeId.TERRAIN
});
var Poly = new Array();
for (var i = 0; i < Lat.length; i++) {
var pos = new google.maps.LatLng(Lat[i], Lng[i]);
Poly.push(pos);
}
var flowlineNonGeodesic = new google.maps.Polyline({
path: Poly,
geodesic: false,
strokeColor: "#00FF00",
strokeOpacity: .8,
strokeWeight: 2,
map: map
});
for (var j = 0; j < Poly.length; j++) {
if (j % 2 == 0) {
var poly = Poly.slice(j, j + 2);
var flowline = new google.maps.Polyline({
path: poly,
geodesic: true,
strokeColor: "#DC143C",
strokeOpacity: .8,
strokeWeight: 2,
icons: [{
icon: lineSymbol,
offset: '100%'
}],
});
flowline.setMap(map);
}
}
}
google.maps.event.addDomListener(window, "load", initMap);
var Lat = [42.365843, 37.756066, 47.450431, 28.431450, 38.898793, 34.040667];
var Lng = [-71.009625, -122.440175, -122.308806, -81.308094, -77.037227, -118.289537];
var lineSymbol = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
};
html,
body,
#map {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map"></div>
This js code is for showing customized Google Maps. I want to add function to this code. URL parameter as ID and show infowindow has this ID on Google Maps. For example "http://www.tabikobo.com/newyork/map/uptown/?=2962"(this ID is 2966).ID is loaded as 'id' in XMLdata.
var uptownMap,defLng = -73.963245,defLat = 40.779438,
san ={
init :
function(){
$(document).ready(function(){
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=san.putGmap";
document.body.appendChild(script);
});
},
putGmap :
function(){
var myLatlng = new google.maps.LatLng(defLat, defLng);
var myOptions = {
zoom: 15,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
uptownMap = new google.maps.Map(document.getElementById("gmapArea"), myOptions);
san.getXmlData();
},
getXmlData : function(){
$.ajax({
type: 'GET',
cache: true,
async: true,
url: '/newyork/map_uptown_xml/',
datatype: 'xml',
success: san.parseXmlData
});
},
parseXmlData: function (xml) {
//a single infowindow for all markers
var infowindow = new google.maps.InfoWindow({
pixelOffset: new google.maps.Size(0, 10)
});
var i = 0,
id, name, url, lat, lng, copy, lead, ename, tag;
$("<ol/>")
.attr('id', 'gmapAnchor')
.appendTo('div#gmapController');
$(xml)
.find('item')
.each(function (i) {
i++;
id = $(this)
.find('description id')
.text();
name = $(this)
.find('description name')
.text();
url = $(this)
.find('description path')
.text();
lat = $(this)
.find('description lat')
.text();
lng = $(this)
.find('description lng')
.text();
tag = $(this)
.find('description tag')
.text();
tag = tag.slice(5, 20);
console.log(tag)
var customIcons = {
hotel:
{
icon: 'http://www.tabikobo.com/newyork/img/icon_hotel.png'
},
var icon = customIcons[tag] || {};
var myLatLng = new google.maps.LatLng(lat, lng);
var beachMarker = new google.maps.Marker({
position: myLatLng,
map: uptownMap,
icon: icon.icon,
});
var htmlTmpl = {
hotel:
{
content: '<div class="infoWinWrapper"><strong><a href="' +
url + '">' + name +
'</a></strong><br />' + ename +
'<br />' + lead + '</div>'
},
};
var htmlTmpl = htmlTmpl[tag] || {};
//click-listener for marker
google.maps.event.addListener(beachMarker, 'click',
function () {
//update the content
infowindow.setContent(
'<div class="hook">' + htmlTmpl
.content + '</div>');
infowindow.open(uptownMap, this);
google.maps.event.addListenerOnce(
infowindow, 'domready',
function () {
var l = $('.hook')
.parent()
.parent()
.parent()
.siblings()
.addClass("infoBox");
});
});
//Creat a Tag
san.putData(name, url, lat, lng, i);
});
},
putData : function(name, url, lat, lng, num){
var x = num;
x += '';
if(x.length == 1){
var y = '0' + x;
}else {
y = x;
}
san.setEvent();
},
setEvent : function(){
$("ul#area_list li a").bind('mouseover', function(){
$(this).parent().find('span.lat').text();
var point = new google.maps.LatLng(
$(this).parent().find('span.lat').text(),
$(this).parent().find('span.lng').text()
);
uptownMap.setZoom(17);
uptownMap.setCenter(point);
});
$("#btnResetZoom a").bind('click', function(){
var point = new google.maps.LatLng(defLat, defLng);
uptownMap.setZoom(15);
uptownMap.setCenter(point);
return false;
});
}
}
window.onload = san.init();
I solived myself! thanks.
var PageMapID = location.href.split('?=');
var PageMapID2 = PageMapID[PageMapID.length -1];
if (id == PageMapID2) {
$(document).ready(function(){
infowindow.open(uptownMap,beachMarker);
infowindow.setContent('<div class="hook">' + htmlTmpl.content + '</div>');
var latlng = new google.maps.LatLng(lat, lng);
uptownMap.setCenter(latlng);
});
}
I'm trying to leave of the mode drawing after draw circle, I want to hide the controls drawingmanager and can edit the circle but I don't know how to do that after to draw the circle enter in mode, don't draw and can edit the circle
<script type="text/javascript">
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(4.705, -74.113),
zoom: 5,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
var drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.MARKER,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [
//google.maps.drawing.OverlayType.MARKER,
google.maps.drawing.OverlayType.CIRCLE,
google.maps.drawing.OverlayType.POLYGON,
//google.maps.drawing.OverlayType.POLYLINE,
//google.maps.drawing.OverlayType.RECTANGLE
]
},
//markerOptions: {icon: 'Images/marker_sprite.png'},
circleOptions: {
strokeColor: '#FF0000',
fillColor: '#DF0101',
fillOpacity: 0.3,
strokeWeight: 2,
editable:true
},
rectangleOptions: {
strokeColor: "#FF0000",
strokeWeight: 2,
fillColor: '#DF0101',
fillOpacity: 0.35,
editable:true
},
polygonOptions: {
strokeColor: "#FF0000",
strokeWeight: 2,
fillColor: '#DF0101',
fillOpacity: 0.35,
editable:true
}
});// Cierre variable drawingManager
drawingManager.setMap(map);
// event handler for drawingManager shapes
function setClickEvent(shape) {
google.maps.event.addListener(shape, 'click', function(){
//Colocar mensaje en Formato Dialgo UI
if(confirm('Desea Eliminar El Punto de Control')){
shape.setMap(null);
drawingManager.setOptions({
drawingMode: google.maps.drawing.OverlayType.MARKER,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [
google.maps.drawing.OverlayType.CIRCLE,
google.maps.drawing.OverlayType.POLYGON
]
}
});
}
});
}
google.maps.event.addListener(drawingManager,'circlecomplete', function(circle){
radius = circle.getRadius();
centro = circle.getCenter();
document.getElementById("posicion").innerHTML=centro;
document.getElementById("radio").innerHTML=radius;
drawingManager.setOptions({
drawingControl: false
});
google.maps.event.addListener(circle, 'radius_changed', function(){
radius = circle.getRadius();
document.getElementById("radio").innerHTML=radius;
});
google.maps.event.addListener(circle, 'center_changed', function(){
centro = circle.getCenter();
document.getElementById("posicion").innerHTML=centro;
});
//drawingManager.setOptions({ drawingControl: false });
setClickEvent(circle);
});
/*
google.maps.event.addListener(drawingManager, 'rectanglecomplete', function(Rectangle) {
var vertices = Rectangle.getBounds();
document.getElementById("posicion").innerHTML=vertices;
setClickEvent(Rectangle);
});
*/
google.maps.event.addListener(drawingManager, 'polygoncomplete', function(Polygon) {
var vertices = Polygon.getPath();
var pocision="";
for (var i=0; i < vertices.length; i++){
var xy=vertices.getAt(i);
pocision += "<br>"+ xy.lng() +" , " + xy.lat();
document.getElementById("posicion").innerHTML=pocision;
}
google.maps.event.addListener(Polygon, 'mousedown', function() {
google.maps.event.addListener(Polygon.getPath(), 'set_at', function() {
console.log('editando');
vertices=Polygon.getPath();
pocision="";
for (var i=0; i < vertices.length; i++){
var xy=vertices.getAt(i);
pocision += "<br>"+ xy.lng() +" , " + xy.lat();
document.getElementById("posicion_Final").innerHTML=pocision;
}
});
});
});
}/* cierra inittalize() */
google.maps.event.addDomListener(window, 'load', initialize);
</script>
To make the circle so it can't be edited, set the editable option to false:
google.maps.event.addListener(drawingManager,'circlecomplete', function(circle){
radius = circle.getRadius();
centro = circle.getCenter();
document.getElementById("posicion").innerHTML=centro;
document.getElementById("radio").innerHTML=radius;
circle.setOptions({editable:false}); // <-- **** add this line
drawingManager.setOptions({
drawingControl: false
});
google.maps.event.addListener(circle, 'radius_changed', function(){
radius = circle.getRadius();
document.getElementById("radio").innerHTML=radius;
});
google.maps.event.addListener(circle, 'center_changed', function(){
centro = circle.getCenter();
document.getElementById("posicion").innerHTML=centro;
});
setClickEvent(circle);
});
Hi I have a map that shows direction of shuttle following are the map and direction initialisation code
var centerLatlng = new google.maps.LatLng(-34.942799,138.553365);
var myOptions = {
zoom: 13,
center: centerLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.LARGE
},
panControl:true,
streetViewControl: false,
OverviewMapControlOptions:
{
opened: true
}
};
var map = new google.maps.Map(document.getElementById("map-guide-google-map"), myOptions);
Following is the Display Direction
function DisplayDirection(directionList){
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer({
markerOptions: {
visible:false
}
});
directionsDisplay.setMap(map);
//Request 0
var increaseSize = 7;
var index =0;
var theoryCurrentEndIndex = index + increaseSize;
var maxmimumIndex = directionList.length-1;
var origin = directionList[index];
var destination = theoryCurrentEndIndex < maxmimumIndex?directionList[theoryCurrentEndIndex]:directionList[maxmimumIndex];
var actualCurrentEndIndex = theoryCurrentEndIndex < maxmimumIndex?theoryCurrentEndIndex: maxmimumIndex;
var waypoints = new Array();
if(actualCurrentEndIndex-index>1) {
for(var i=index+1;i<actualCurrentEndIndex;i++) {
waypoints.push(
{
location:directionList[i],
stopover:true}
);
}
}
var request = {
origin: origin,
destination: destination,
waypoints : waypoints,
provideRouteAlternatives:false,
travelMode: google.maps.TravelMode.WALKING,
unitSystem: google.maps.UnitSystem.METRIC
}
directionsService.route(request, function(result, status) {
if(status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
}) ;
}
How can I reset the LatLongBounds to show all the stop points and centre the map