简体   繁体   English

在Google地图api中加载多边形

[英]Load polygon in Google map api

I want to implement like user can draw a area in google map from our application. 我想实现像用户可以从我们的应用程序中绘制谷歌地图中的区域。 Then when he come back, then should load the data which is previously drew by him/her. 然后当他回来时,应该加载之前由他/她绘制的数据。

I've done two way of method. 我已经做了两种方法。 One is, 一个是,

  1. Using Drawing manager. 使用绘图管理器。

    Drawing Polygon in google map using javascript 使用javascript在谷歌地图中绘制多边形

    https://developers.google.com/maps/documentation/javascript/drawinglayer https://developers.google.com/maps/documentation/javascript/drawinglayer

  2. Using Google map api data layer. 使用谷歌地图api数据层。 http://jsfiddle.net/dg9e93qy/

From the first method, I can allow user to drag, and can restrict user from drawing multiple polygons. 从第一种方法,我可以允许用户拖动,并可以限制用户绘制多个多边形。 But I cannot load the polygons again to this drawing. 但我无法再将多边形加载到此图形中。 But I found somewhere that we can load the polygons. 但我找到了可以加载多边形的地方。 https://developers.google.com/maps/documentation/javascript/examples/polygon-simple . https://developers.google.com/maps/documentation/javascript/examples/polygon-simple

But this is using the polygon instance to show the polygons not the drawing. 但这是使用多边形实例来显示多边形而不是绘图。

Here I need any other two solutions. 在这里我需要任何其他两个解决方案

  • Whether I should load the polygon data to the map using drawing. 是否应该使用绘图将多边形数据加载到地图中。

  • Should enable drawing option using polygon https://developers.google.com/maps/documentation/javascript/examples/polygon-simple 应使用多边形启用绘图选项https://developers.google.com/maps/documentation/javascript/examples/polygon-simple

From the Second method, I can get the coordinates, and can load the polygon again. 从第二种方法,我可以得到坐标,并可以再次加载多边形。 But I cannot get the polygon area from that. 但是我无法从中得到多边形区域。 (Actually I am getting the geoJson data) (实际上我得到了geoJson数据)

Here I cannot get the Area for Drawn place. 在这里,我无法获得绘制场所的区域。 How to do that? 怎么做?

Any answer from the first method or the second methods is good. 第一种方法或第二种方法的任何答案都是好的。

I have done alternate that, created polygon instead of loading in the same drawing manager. 我做了替代,创建了多边形,而不是在同一个绘图管理器中加载。

After drawing complete, removed drawing manager and then created the polygon. 绘制完成后,删除绘图管理器,然后创建多边形。 Then had a separate button to remove the polygon from the map. 然后有一个单独的按钮从地图中删除多边形。

If we remove the polygon, then removed the polygon from the map and recreated the drawing manger. 如果我们删除多边形,则从地图中删除多边形并重新创建绘图管理器。

This solved my issue. 这解决了我的问题。

drawingManager.setMap(null);
                    bermudaTriangle = new google.maps.Polygon({
                        paths: polygonsArray,
                        strokeColor: '#FF0000',
                        strokeOpacity: 0.8,
                        strokeWeight: 2,
                        fillColor: '#FF0000',
                        fillOpacity: 0.35
                        //,editable: true
                    });
                    bermudaTriangle.setMap(map);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM