对于有角度的Google地图,我希望可以将存储的标记多边形数组绘制到地图上。
我使用的技术是:带有JavaScript的Angular版本1,使用angular指令和templateUrl。
这是我的html指令模板:
<ui-gmap-google-map center="config.map.center" zoom="config.map.zoom" options="config.map.options" events="config.map.events" draggable="true">
<ui-gmap-polygon path="compatiblePolygon" stroke="polygonConfig.stroke" fill="polygonConfig.fill" fit="true" static="true" visible="polygonConfig.visible" editable="polygonConfig.editable" draggable="polygonConfig.draggable" clickable="true" events="polygonConfig.events">
</ui-gmap-polygon>
<ui-gmap-markers models="compatiblePoints" coords="'self'" idKey="'id'"
options="pointsConfig.options"
clickable="true">
</ui-gmap-markers>
<ui-gmap-drawing-manager options="config.drawing.options" static="true" control="drawingManagerControl" events="config.drawing.events"></ui-gmap-drawing-manager>
</ui-gmap-google-map>
您需要将多边形作为编码字符串存储在数据库中,而不是多边形坐标。您可以按以下方式获取编码的多边形:
/* This function save latitude and longitude to the polygons[] variable after we call it. */
function encodePolygon(polygon)
{
//This variable gets all bounds of polygon.
var path = polygon.getPath();
var encodeString =
google.maps.geometry.encoding.encodePath(path);
/* store encodeString in database */
}
然后,您可以随时使用以下方法从编码字符串中重绘多边形:
function DrawPolygon(encodedString){
var decodedPolygon =
google.maps.geometry.encoding.decodePath(encodedString);
var polygon = new google.maps.Polygon({
paths: decodedPolygon,
editable: false,
strokeColor: '#FFFF',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FFFF',
fillOpacity: 0.35
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句