Adding polygon and infobox to Google map (JS)

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question



























    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?







    share|improve this question























      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?







      share|improve this question













      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?









      share|improve this question












      share|improve this question




      share|improve this question








      edited Feb 26 at 10:38









      Vogel612♦

      20.9k345124




      20.9k345124









      asked Feb 26 at 10:24









      Евгений Сухомлин

      11




      11

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          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



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          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













































































          Popular posts from this blog

          Greedy Best First Search implementation in Rust

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          C++11 CLH Lock Implementation