Adding polygon and infobox to Google map (JS)
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
I have code to add a Polygon object as defined in a file to a google map
Here is my initMap
function
function initMap()
//translations is a global variable from the view that contains translations (Description and Text)
dictionary.addRange(translations);
mapWrapper = new MapWrapper('mapDiv', enableClustering: false );
map = mapWrapper.getMap();
var mapDiv = map.getDiv();
map.setOptions(
fullscreenControl: true,
scaleControl: true
);
map.addListener('click', function (event)
if (selectedShape)
selectedShape.setEditable(false);
google.maps.event.trigger(selectedShape, 'edit_end');
selectedShape = undefined;
);
function disableAutoZoom()
$('#checkAutoZoom').prop('checked', false);
map.addListener('dragstart', disableAutoZoom);
map.addListener('dblclick', disableAutoZoom);
//the following 3 event handlers all handle the same event on different browsers/versions
//they are also added with useCapture: true, because google maps stops propagation of these events
mapDiv.addEventListener('mousewheel', disableAutoZoom, true);
mapDiv.addEventListener('DOMMouseScroll', disableAutoZoom, true);
mapDiv.addEventListener('wheel', disableAutoZoom, true);
drawingManager = new google.maps.drawing.DrawingManager(
drawingMode: google.maps.drawing.OverlayType.RECTANGLE,
drawingControlOptions:
drawingModes: [
google.maps.drawing.OverlayType.RECTANGLE,
google.maps.drawing.OverlayType.POLYGON
]
);
drawingManager.addListener('polygoncomplete', function (polygon)
currentShape = addPolygonPlace('unsaved', polygon.getPath().getArray(), '');
polygon.setMap(null);
drawingManager.setMap();
);
In this function in polygoncomplete
event I have addPolygonPlace
function
Here is code of this function
function addPolygonPlace(id, paths, colors)
let place = new Polygon(id, paths, colors);
mapWrapper.addPlace(place);
var infoWindow = new google.maps.InfoWindow();
place.addEventListener('mouseover', function ()
// placeInfobox.update(place);
// placeInfobox.show();
infoWindow.setContent("Unsaved:");
var bounds = new google.maps.LatLngBounds();
var i;
for (i = 0; i < place.paths.length; i++)
bounds.extend(place.paths[i]);
//get center of polygon to set info window
infoWindow.setPosition(bounds.getCenter());
infoWindow.open(map);
);
place.addEventListener('mouseout', function ()
//placeInfobox.hide();
infoWindow.close(map);
);
place.addEventListener('click', function ()
if (selectedShape)
selectedShape.setEditable(false);
google.maps.event.trigger(selectedShape, 'edit_end');
place.setEditable(true);
selectedShape = place;
);
google.maps.event.addListener(place, 'edit_end', function ()
if (place.id === 'unsaved')
return;
let placeToEdit = getPlaceByDescription(place.id);
let path = place.googleEntity.getPath().getArray();
updatePlace(place.id);
);
return place;
As you can see I use here Polygon object. It comes from file, where I have Polygon object.
Here is code of this object.
var Polygon = (function ()
'use strict';
let colors = ;
function Polygon(id, paths, infoboxDescription, colors) colors === null)
colors = fillColor: '#006400', strokeColor: '#646464' ;
if (colors.fillColor === undefined
Object.defineProperty(Polygon.prototype, 'visible',
get: function () (this._visible = false); ,
enumerable: true,
configurable: true
);
Polygon.prototype.remove = function ()
this.googleEntity.setMap(null);
Polygon.prototype.addEventListener = function (eventName, callback)
this.googleEntity.addListener(eventName, callback.bind(this));
Polygon.prototype.setEditable = function (editable)
this.googleEntity.setEditable(editable);
return Polygon
)()
All works great.
Is there any way to make this code better?
javascript jquery google-maps
add a comment |Â
up vote
0
down vote
favorite
I have code to add a Polygon object as defined in a file to a google map
Here is my initMap
function
function initMap()
//translations is a global variable from the view that contains translations (Description and Text)
dictionary.addRange(translations);
mapWrapper = new MapWrapper('mapDiv', enableClustering: false );
map = mapWrapper.getMap();
var mapDiv = map.getDiv();
map.setOptions(
fullscreenControl: true,
scaleControl: true
);
map.addListener('click', function (event)
if (selectedShape)
selectedShape.setEditable(false);
google.maps.event.trigger(selectedShape, 'edit_end');
selectedShape = undefined;
);
function disableAutoZoom()
$('#checkAutoZoom').prop('checked', false);
map.addListener('dragstart', disableAutoZoom);
map.addListener('dblclick', disableAutoZoom);
//the following 3 event handlers all handle the same event on different browsers/versions
//they are also added with useCapture: true, because google maps stops propagation of these events
mapDiv.addEventListener('mousewheel', disableAutoZoom, true);
mapDiv.addEventListener('DOMMouseScroll', disableAutoZoom, true);
mapDiv.addEventListener('wheel', disableAutoZoom, true);
drawingManager = new google.maps.drawing.DrawingManager(
drawingMode: google.maps.drawing.OverlayType.RECTANGLE,
drawingControlOptions:
drawingModes: [
google.maps.drawing.OverlayType.RECTANGLE,
google.maps.drawing.OverlayType.POLYGON
]
);
drawingManager.addListener('polygoncomplete', function (polygon)
currentShape = addPolygonPlace('unsaved', polygon.getPath().getArray(), '');
polygon.setMap(null);
drawingManager.setMap();
);
In this function in polygoncomplete
event I have addPolygonPlace
function
Here is code of this function
function addPolygonPlace(id, paths, colors)
let place = new Polygon(id, paths, colors);
mapWrapper.addPlace(place);
var infoWindow = new google.maps.InfoWindow();
place.addEventListener('mouseover', function ()
// placeInfobox.update(place);
// placeInfobox.show();
infoWindow.setContent("Unsaved:");
var bounds = new google.maps.LatLngBounds();
var i;
for (i = 0; i < place.paths.length; i++)
bounds.extend(place.paths[i]);
//get center of polygon to set info window
infoWindow.setPosition(bounds.getCenter());
infoWindow.open(map);
);
place.addEventListener('mouseout', function ()
//placeInfobox.hide();
infoWindow.close(map);
);
place.addEventListener('click', function ()
if (selectedShape)
selectedShape.setEditable(false);
google.maps.event.trigger(selectedShape, 'edit_end');
place.setEditable(true);
selectedShape = place;
);
google.maps.event.addListener(place, 'edit_end', function ()
if (place.id === 'unsaved')
return;
let placeToEdit = getPlaceByDescription(place.id);
let path = place.googleEntity.getPath().getArray();
updatePlace(place.id);
);
return place;
As you can see I use here Polygon object. It comes from file, where I have Polygon object.
Here is code of this object.
var Polygon = (function ()
'use strict';
let colors = ;
function Polygon(id, paths, infoboxDescription, colors) colors === null)
colors = fillColor: '#006400', strokeColor: '#646464' ;
if (colors.fillColor === undefined
Object.defineProperty(Polygon.prototype, 'visible',
get: function () (this._visible = false); ,
enumerable: true,
configurable: true
);
Polygon.prototype.remove = function ()
this.googleEntity.setMap(null);
Polygon.prototype.addEventListener = function (eventName, callback)
this.googleEntity.addListener(eventName, callback.bind(this));
Polygon.prototype.setEditable = function (editable)
this.googleEntity.setEditable(editable);
return Polygon
)()
All works great.
Is there any way to make this code better?
javascript jquery google-maps
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have code to add a Polygon object as defined in a file to a google map
Here is my initMap
function
function initMap()
//translations is a global variable from the view that contains translations (Description and Text)
dictionary.addRange(translations);
mapWrapper = new MapWrapper('mapDiv', enableClustering: false );
map = mapWrapper.getMap();
var mapDiv = map.getDiv();
map.setOptions(
fullscreenControl: true,
scaleControl: true
);
map.addListener('click', function (event)
if (selectedShape)
selectedShape.setEditable(false);
google.maps.event.trigger(selectedShape, 'edit_end');
selectedShape = undefined;
);
function disableAutoZoom()
$('#checkAutoZoom').prop('checked', false);
map.addListener('dragstart', disableAutoZoom);
map.addListener('dblclick', disableAutoZoom);
//the following 3 event handlers all handle the same event on different browsers/versions
//they are also added with useCapture: true, because google maps stops propagation of these events
mapDiv.addEventListener('mousewheel', disableAutoZoom, true);
mapDiv.addEventListener('DOMMouseScroll', disableAutoZoom, true);
mapDiv.addEventListener('wheel', disableAutoZoom, true);
drawingManager = new google.maps.drawing.DrawingManager(
drawingMode: google.maps.drawing.OverlayType.RECTANGLE,
drawingControlOptions:
drawingModes: [
google.maps.drawing.OverlayType.RECTANGLE,
google.maps.drawing.OverlayType.POLYGON
]
);
drawingManager.addListener('polygoncomplete', function (polygon)
currentShape = addPolygonPlace('unsaved', polygon.getPath().getArray(), '');
polygon.setMap(null);
drawingManager.setMap();
);
In this function in polygoncomplete
event I have addPolygonPlace
function
Here is code of this function
function addPolygonPlace(id, paths, colors)
let place = new Polygon(id, paths, colors);
mapWrapper.addPlace(place);
var infoWindow = new google.maps.InfoWindow();
place.addEventListener('mouseover', function ()
// placeInfobox.update(place);
// placeInfobox.show();
infoWindow.setContent("Unsaved:");
var bounds = new google.maps.LatLngBounds();
var i;
for (i = 0; i < place.paths.length; i++)
bounds.extend(place.paths[i]);
//get center of polygon to set info window
infoWindow.setPosition(bounds.getCenter());
infoWindow.open(map);
);
place.addEventListener('mouseout', function ()
//placeInfobox.hide();
infoWindow.close(map);
);
place.addEventListener('click', function ()
if (selectedShape)
selectedShape.setEditable(false);
google.maps.event.trigger(selectedShape, 'edit_end');
place.setEditable(true);
selectedShape = place;
);
google.maps.event.addListener(place, 'edit_end', function ()
if (place.id === 'unsaved')
return;
let placeToEdit = getPlaceByDescription(place.id);
let path = place.googleEntity.getPath().getArray();
updatePlace(place.id);
);
return place;
As you can see I use here Polygon object. It comes from file, where I have Polygon object.
Here is code of this object.
var Polygon = (function ()
'use strict';
let colors = ;
function Polygon(id, paths, infoboxDescription, colors) colors === null)
colors = fillColor: '#006400', strokeColor: '#646464' ;
if (colors.fillColor === undefined
Object.defineProperty(Polygon.prototype, 'visible',
get: function () (this._visible = false); ,
enumerable: true,
configurable: true
);
Polygon.prototype.remove = function ()
this.googleEntity.setMap(null);
Polygon.prototype.addEventListener = function (eventName, callback)
this.googleEntity.addListener(eventName, callback.bind(this));
Polygon.prototype.setEditable = function (editable)
this.googleEntity.setEditable(editable);
return Polygon
)()
All works great.
Is there any way to make this code better?
javascript jquery google-maps
I have code to add a Polygon object as defined in a file to a google map
Here is my initMap
function
function initMap()
//translations is a global variable from the view that contains translations (Description and Text)
dictionary.addRange(translations);
mapWrapper = new MapWrapper('mapDiv', enableClustering: false );
map = mapWrapper.getMap();
var mapDiv = map.getDiv();
map.setOptions(
fullscreenControl: true,
scaleControl: true
);
map.addListener('click', function (event)
if (selectedShape)
selectedShape.setEditable(false);
google.maps.event.trigger(selectedShape, 'edit_end');
selectedShape = undefined;
);
function disableAutoZoom()
$('#checkAutoZoom').prop('checked', false);
map.addListener('dragstart', disableAutoZoom);
map.addListener('dblclick', disableAutoZoom);
//the following 3 event handlers all handle the same event on different browsers/versions
//they are also added with useCapture: true, because google maps stops propagation of these events
mapDiv.addEventListener('mousewheel', disableAutoZoom, true);
mapDiv.addEventListener('DOMMouseScroll', disableAutoZoom, true);
mapDiv.addEventListener('wheel', disableAutoZoom, true);
drawingManager = new google.maps.drawing.DrawingManager(
drawingMode: google.maps.drawing.OverlayType.RECTANGLE,
drawingControlOptions:
drawingModes: [
google.maps.drawing.OverlayType.RECTANGLE,
google.maps.drawing.OverlayType.POLYGON
]
);
drawingManager.addListener('polygoncomplete', function (polygon)
currentShape = addPolygonPlace('unsaved', polygon.getPath().getArray(), '');
polygon.setMap(null);
drawingManager.setMap();
);
In this function in polygoncomplete
event I have addPolygonPlace
function
Here is code of this function
function addPolygonPlace(id, paths, colors)
let place = new Polygon(id, paths, colors);
mapWrapper.addPlace(place);
var infoWindow = new google.maps.InfoWindow();
place.addEventListener('mouseover', function ()
// placeInfobox.update(place);
// placeInfobox.show();
infoWindow.setContent("Unsaved:");
var bounds = new google.maps.LatLngBounds();
var i;
for (i = 0; i < place.paths.length; i++)
bounds.extend(place.paths[i]);
//get center of polygon to set info window
infoWindow.setPosition(bounds.getCenter());
infoWindow.open(map);
);
place.addEventListener('mouseout', function ()
//placeInfobox.hide();
infoWindow.close(map);
);
place.addEventListener('click', function ()
if (selectedShape)
selectedShape.setEditable(false);
google.maps.event.trigger(selectedShape, 'edit_end');
place.setEditable(true);
selectedShape = place;
);
google.maps.event.addListener(place, 'edit_end', function ()
if (place.id === 'unsaved')
return;
let placeToEdit = getPlaceByDescription(place.id);
let path = place.googleEntity.getPath().getArray();
updatePlace(place.id);
);
return place;
As you can see I use here Polygon object. It comes from file, where I have Polygon object.
Here is code of this object.
var Polygon = (function ()
'use strict';
let colors = ;
function Polygon(id, paths, infoboxDescription, colors) colors === null)
colors = fillColor: '#006400', strokeColor: '#646464' ;
if (colors.fillColor === undefined
Object.defineProperty(Polygon.prototype, 'visible',
get: function () (this._visible = false); ,
enumerable: true,
configurable: true
);
Polygon.prototype.remove = function ()
this.googleEntity.setMap(null);
Polygon.prototype.addEventListener = function (eventName, callback)
this.googleEntity.addListener(eventName, callback.bind(this));
Polygon.prototype.setEditable = function (editable)
this.googleEntity.setEditable(editable);
return Polygon
)()
All works great.
Is there any way to make this code better?
javascript jquery google-maps
edited Feb 26 at 10:38
Vogel612â¦
20.9k345124
20.9k345124
asked Feb 26 at 10:24
ÃÂòóõýøù áÃÂàþüûøý
11
11
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f188363%2fadding-polygon-and-infobox-to-google-map-js%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password