duanouyong4228 2016-08-31 13:04
浏览 41

OL3在db中保存单个功能

Good day,

I have final changes of feature on draw.on("drawend") also on drawend i try to export feature

var feature = event.feature;
var cache = [];
jsonFeature = JSON.stringify(
    feature,
    function(key, value) {
        if (typeof value === "object" && value !== null) {
            if (cache.indexOf(value) !== -1) {
                return;
            }

            cache.push(value);
        }

        return value;
    }
);
cache = null;

and trying to pass it to RPC layer to save to database, but after converting it back to Object i get errors

var clone = JSON.parse(jsonFeature);
vectorSource.addFeature(clone);

Uncaught TypeError: feature.getId is not a function

How can i correctly pass feature or split feature into array to save it into DB via PHP and then return it back from DB to ol.source.Vector with all styles, images, canvas, coordinates, etc.?

Every feature contains it's own styling, some of them, like marker, have image and some, like arrowLine, have canvas of arrows head at LineString event.feature.getGeometry().getLastCoordinate();

** Edit **

Found solution by using ol.format.KML

var kml = new ol.format.KML();
var jsonFeature = kml.writeFeatures([feature]);

but still is some problems:

  1. can't save circle - Uncaught TypeError: Cannot read property 'call' of undefined
  2. polygon that concatenates to last coordinate (arrow head) doesn't exists in xml, i guess i need somehow merge LineString with Polygon
  3. i draw element in canvas and placing it on LineString, after convertation to ol.format.KML i receive bad XML where canvas is converted into <href>100</href> and after reading this part i receive error about URL
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 stm32开发clion时遇到的编译问题