How to use the @supermap/iclient-common.GeoJSON function in @supermap/iclient-common

To help you get started, we’ve selected a few @supermap/iclient-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SuperMap / iClient-JavaScript / src / openlayers / overlay / theme / Theme.js View on Github external
continue;
            } else if (features[i] instanceof ol.Feature) {
                //ol.Feature 数据类型
                //_toFeature 统一处理 ol.Feature 所有 geometry 类型
                featuresTemp.push(this._toFeature(features[i]));
                continue;
            } else if (features[i] instanceof GeometryVector) {
                // 若是 GeometryVector 直接返回
                featuresTemp.push(features[i]);
                continue;
            } else if (features[i].geometry && features[i].geometry.parts) {
                //iServer服务器返回数据格式
                featuresTemp.push(ServerFeature.fromJson(features[i]).toFeature());
            } else if (["FeatureCollection", "Feature", "Geometry"].indexOf(features[i].type) != -1) {
                //GeoJSON 规范数据类型
                const format = new GeoJSONFormat();
                featuresTemp = featuresTemp.concat(format.read(features[i]));
            } else {
                throw new Error(`features[${i}]'s type is not be supported.`);
            }

        }
        return featuresTemp;
    }
github SuperMap / iClient-JavaScript / src / openlayers / overlay / theme / Theme.js View on Github external
_toFeature(feature) {
        let geoFeature = (new ol.format.GeoJSON()).writeFeature(feature);
        return new GeoJSONFormat().read(geoFeature, "Feature");
    }
github SuperMap / iClient-JavaScript / src / openlayers / overlay / HeatMap.js View on Github external
toiClientFeature(features) {
        if (!Util.isArray(features)) {
            features = [features];
        }
        let featuresTemp = [], geometry, attributes;
        for (let i = 0, len = features.length; i < len; i++) {
            if (features[i] instanceof ol.Feature) {
                //热点图支支持传入点对象要素
                if (features[i].getGeometry() instanceof ol.geom.Point) {
                    geometry = new GeometryPoint(features[i].getGeometry().getCoordinates()[0], features[i].getGeometry().getCoordinates()[1]);
                    //固定属性字段为 "Properties"
                    attributes = features[i].getProperties()["Properties"] ? features[i].getProperties()["Properties"] : {};
                    featuresTemp.push(new GeometryVector(geometry, attributes));
                }
            } else if (["FeatureCollection", "Feature", "Geometry"].indexOf(features[i].type) != -1) {
                let format = new GeoJSONFormat();
                featuresTemp = featuresTemp.concat(format.read(features[i]));
            } else if (features[i].geometry && features[i].geometry.parts) {
                //iServer服务器返回数据格式
                featuresTemp.push(ServerFeature.fromJson(features[i]).toFeature());
            } else {
                throw new Error(`Features[${i}]'s type does not match, please check.`);
            }
        }
        return featuresTemp;
    }
github SuperMap / iClient-JavaScript / src / leaflet / overlay / theme / ThemeFeature.js View on Github external
toFeature: function () {
        let geometry = this.geometry;
        const points = [];
        let geojsonObject
        if (geometry.toGeoJSON) {
            geojsonObject = geometry.toGeoJSON();
            geojsonObject.properties = this.attributes;
            return new GeoJSON().read(geojsonObject)[0];
        }
        if (geometry.length === 3) {
            geometry = new GeoText(geometry[1], geometry[0], geometry[2]);
        } else if (geometry.length === 2) {
            geometry = new GeometryPoint(points[0], points[1]);
        } else if (geometry instanceof L.LatLng) {
            geometry = new GeometryPoint(geometry.lng, geometry.lat);
        } else if (geometry instanceof L.Point) {
            geometry = new GeometryPoint(geometry.x, geometry.y);
        } else if (geometry instanceof L.CircleMarker) {
            var latLng = geometry.getLatLng();
            geometry = new GeometryPoint(latLng.lng, latLng.lat);
        }
        return new Vector(geometry, this.attributes);
    },
github SuperMap / iClient-JavaScript / src / leaflet / overlay / HeatMapLayer.js View on Github external
toiClientFeature: function (features) {
        if (!L.Util.isArray(features)) {
            features = [features];
        }
        let featuresTemp = [];
        for (let i = 0, len = features.length; i < len; i++) {
            //支持ThemeFeature类型的feature
            //支持传入ThemeFeature类型,ThemeFeature.geometry instanceof L.LatLng | ThemeFeature.geometry instanceof L.Point
            if (features[i] instanceof HeatMapFeature) {
                featuresTemp.push(features[i].toFeature());
            } else if (["FeatureCollection", "Feature", "Geometry"].indexOf(features[i].type) != -1) {
                const format = new GeoJSONFormat();
                featuresTemp = featuresTemp.concat(format.read(features[i]));
            } else if (features[i].geometry && features[i].geometry.parts) {
                //iServer服务器返回数据格式 todo 暂未找到更好的参数判断,暂用 geometry.parts 试用
                featuresTemp.push(ServerFeature.fromJson(features[i]).toFeature());
            } else {
                throw new Error("Features's type does not match, please check.");
            }
        }
        return featuresTemp;
    },
github SuperMap / iClient-JavaScript / src / openlayers / core / Util.js View on Github external
static toGeoJSON(smObj) {
        if (smObj) {
            var format = new GeoJSONFormat();
            return format.toGeoJSON(smObj);
        }
    }
github SuperMap / iClient-JavaScript / src / leaflet / core / Util.js View on Github external
export var toGeoJSON = function(feature) {
    if (!feature) {
        return feature;
    }
    return new GeoJSONFormat().toGeoJSON(feature);
};
export var toSuperMapGeometry = function(geometry) {
github SuperMap / iClient-JavaScript / src / leaflet / mapping / WebMap.js View on Github external
parseFeatureFromJson: function (feature) {
        var format = new GeoJSONFormat();
        var features = format.read(feature);
        //兼容insights数据格式
        if (features == null) {
            var content = JSON.parse(feature.replace(/'/, '"'));
            if (content.isAnalyseResult || content.type === 'MapEditor' || content.type === 'DataInsights' || content.type === 'ISERVER') {
                content = content.data.recordsets[0].features;
            }
            format = new GeoJSONFormat();
            features = format.read(content);
        }
        for (var i = 0, len = features.length; i < len; i++) {
            features[i].attributes = features[i].attributes.properties || features[i].attributes;
        }
        return features;

    },
github SuperMap / iClient-JavaScript / src / leaflet / mapping / WebMap.js View on Github external
function addFeatures(features) {
            if (layer && layer.labelLayer instanceof LabelThemeLayer) {
                me.addFeature2LabelLayer(layer.labelLayer, features, layerInfo);
            }
            if (L.HeatLayer && layer instanceof L.HeatLayer) {
                var heatPoints = [];
                for (let i = 0, len = features.length; i < len; i++) {
                    let geometry = features[i].geometry;
                    heatPoints[i] = L.latLng(geometry.y, geometry.x);
                    if (layer.options.featureWeight) {
                        heatPoints[i] = [heatPoints[i].lat, heatPoints[i].lng, parseFloat(features[i].attributes[layer.options.featureWeight])];
                    }
                }
                layer.setLatLngs(heatPoints);
            } else if (layer instanceof L.GeoJSON) {
                layer.addData(new GeoJSONFormat().toGeoJSON(features));
            } else {
                layer.addFeatures(features);
            }

        }
    },