使用JSON.stringify和JSON.parse将多边形坐标存储到oracle中 [英] use JSON.stringify and JSON.parse to store polygon coordinates into oracle

查看:129
本文介绍了使用JSON.stringify和JSON.parse将多边形坐标存储到oracle中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将google地图多边形覆盖的坐标存储到oracle中并在下一个会话中显示它。有代码:

$ p $ function savePolygons(){
$ .post('oracle_deletePolygons.php');
为(VAR I = 0; I< createdShapes.length;我++){
变种nom_zone =逃逸(的document.getElementById( nom_zone_ + createdShapes [I] .ID)。价值);
var couleur = escape(createdShapes [i] .fillColor);
var code_cs = escape('711');
var shapeid_export = escape(createdShapes [i] .id);
var geometry = createdShapes [i] .getPath()。getArray();
geometry = JSON.stringify(geometry);
VAR URL1 = ?oracle_savePolygons.php nom_zone = + nom_zone + &安培;传送彩色与存储= +传送彩色+ &安培; code_cs = + code_cs + &安培; shapeid_export = + shapeid_export +&安培;几何= +几何;
$ .get(url1);


$ / code $ / pre

我使用JSON.stringify将文本转换为路径

  [{Ya:53.4357192066942,Za: -  75.82763671875},{雅 :52.40241887397331, 杂 : -  77.3876953125},{ 雅 :51.781435604431195 杂: -  74.0478515625}] 

在使用php将数据解析为javascript var后,我使用JSON.parse将字符串转换回像这样的坐标数组以重建多边形:

  function addPolygons(shapeId_import,nom_zone,couleur,geometry){
geometry = JSON.parse(geometry);
var newPolygon = new google.maps.Polygon({
路径:geometry,
fillColor:couleur,
fillOpacity:0.45,
strokeWeight:1,
可编辑:false,
shapeid:shapeId_import,
map:map
});

不幸的是,它不工作。我不能用这个新阵列重建多边形。你能告诉我如何重建多边形的方式吗?解决方案JSON.stringify()不会保留原始的MVCArray,



您最好使用 google.maps.geometry.encoding.encodePath()创建一个可存储的值并在重新使用之前对其进行解码。

I want to store the coordinates of a google maps polygon overlay into oracle and display it on next session. There is the code:

function savePolygons(){
    $.post('oracle_deletePolygons.php');
    for (var i = 0; i < createdShapes.length; i++){
        var nom_zone  = escape(document.getElementById('nom_zone_' + createdShapes[i].id).value);
        var couleur = escape(createdShapes[i].fillColor);
        var code_cs = escape('711');
        var shapeid_export = escape(createdShapes[i].id);
        var geometry = createdShapes[i].getPath().getArray();
        geometry = JSON.stringify(geometry);
        var url1 = "oracle_savePolygons.php?nom_zone=" + nom_zone + "&couleur=" + couleur + "&code_cs=" + code_cs + "&shapeid_export=" + shapeid_export + "&geometry=" + geometry;
        $.get(url1);
    }   
}

I use JSON.stringify to convert into text the path array of the polygon which return this:

[{"Ya":53.4357192066942,"Za":-75.82763671875},{"Ya":52.40241887397331,"Za":-77.3876953125},{"Ya":51.781435604431195,"Za":-74.0478515625}]

After using php to parse the data of the oracle table into javascript var, I use JSON.parse to convert the string back to array of coordinates like that in order to rebuild the polygons:

function addPolygons(shapeId_import, nom_zone, couleur, geometry){
    geometry = JSON.parse(geometry);
    var newPolygon = new google.maps.Polygon({
        paths: geometry,
        fillColor: couleur,
        fillOpacity: 0.45,
        strokeWeight: 1,
        editable: false,
        shapeid: shapeId_import,
        map:map
    });

Unfortunately, its not working. I cant rebuild polygon with this new array. Can you tell me how to rebuild the polygon that way?

解决方案

JSON.stringify() will not keep the original MVCArray, the constructor is missing.

You better use google.maps.geometry.encoding.encodePath() to create a storable value and decode it before re-using it.

这篇关于使用JSON.stringify和JSON.parse将多边形坐标存储到oracle中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆