Merge pull request #7005 from Sol1du2/issue/6992/EsriJsonFormat

Add spatial reference inside geometry in EsriFormat
This commit is contained in:
Bart van den Eijnden
2017-07-27 14:40:02 +02:00
committed by GitHub
+13 -13
View File
@@ -304,7 +304,7 @@ ol.format.EsriJSON.getHasZM_ = function(geometry) {
* @return {EsriJSONPolyline} EsriJSON geometry. * @return {EsriJSONPolyline} EsriJSON geometry.
*/ */
ol.format.EsriJSON.writeLineStringGeometry_ = function(geometry, opt_options) { ol.format.EsriJSON.writeLineStringGeometry_ = function(geometry, opt_options) {
var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.LineString} */ (geometry)); var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.LineString} */(geometry));
return /** @type {EsriJSONPolyline} */ ({ return /** @type {EsriJSONPolyline} */ ({
hasZ: hasZM.hasZ, hasZ: hasZM.hasZ,
hasM: hasZM.hasM, hasM: hasZM.hasM,
@@ -323,7 +323,7 @@ ol.format.EsriJSON.writeLineStringGeometry_ = function(geometry, opt_options) {
*/ */
ol.format.EsriJSON.writePolygonGeometry_ = function(geometry, opt_options) { ol.format.EsriJSON.writePolygonGeometry_ = function(geometry, opt_options) {
// Esri geometries use the left-hand rule // Esri geometries use the left-hand rule
var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.Polygon} */ (geometry)); var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.Polygon} */(geometry));
return /** @type {EsriJSONPolygon} */ ({ return /** @type {EsriJSONPolygon} */ ({
hasZ: hasZM.hasZ, hasZ: hasZM.hasZ,
hasM: hasZM.hasM, hasM: hasZM.hasM,
@@ -339,7 +339,7 @@ ol.format.EsriJSON.writePolygonGeometry_ = function(geometry, opt_options) {
* @return {EsriJSONPolyline} EsriJSON geometry. * @return {EsriJSONPolyline} EsriJSON geometry.
*/ */
ol.format.EsriJSON.writeMultiLineStringGeometry_ = function(geometry, opt_options) { ol.format.EsriJSON.writeMultiLineStringGeometry_ = function(geometry, opt_options) {
var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.MultiLineString} */ (geometry)); var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.MultiLineString} */(geometry));
return /** @type {EsriJSONPolyline} */ ({ return /** @type {EsriJSONPolyline} */ ({
hasZ: hasZM.hasZ, hasZ: hasZM.hasZ,
hasM: hasZM.hasM, hasM: hasZM.hasM,
@@ -355,7 +355,7 @@ ol.format.EsriJSON.writeMultiLineStringGeometry_ = function(geometry, opt_option
* @return {EsriJSONMultipoint} EsriJSON geometry. * @return {EsriJSONMultipoint} EsriJSON geometry.
*/ */
ol.format.EsriJSON.writeMultiPointGeometry_ = function(geometry, opt_options) { ol.format.EsriJSON.writeMultiPointGeometry_ = function(geometry, opt_options) {
var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.MultiPoint} */ (geometry)); var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.MultiPoint} */(geometry));
return /** @type {EsriJSONMultipoint} */ ({ return /** @type {EsriJSONMultipoint} */ ({
hasZ: hasZM.hasZ, hasZ: hasZM.hasZ,
hasM: hasZM.hasM, hasM: hasZM.hasM,
@@ -372,7 +372,7 @@ ol.format.EsriJSON.writeMultiPointGeometry_ = function(geometry, opt_options) {
*/ */
ol.format.EsriJSON.writeMultiPolygonGeometry_ = function(geometry, ol.format.EsriJSON.writeMultiPolygonGeometry_ = function(geometry,
opt_options) { opt_options) {
var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.MultiPolygon} */ (geometry)); var hasZM = ol.format.EsriJSON.getHasZM_(/** @type {ol.geom.MultiPolygon} */(geometry));
var coordinates = /** @type {ol.geom.MultiPolygon} */ (geometry).getCoordinates(false); var coordinates = /** @type {ol.geom.MultiPolygon} */ (geometry).getCoordinates(false);
var output = []; var output = [];
for (var i = 0; i < coordinates.length; i++) { for (var i = 0; i < coordinates.length; i++) {
@@ -523,7 +523,7 @@ ol.format.EsriJSON.prototype.readGeometry;
ol.format.EsriJSON.prototype.readGeometryFromObject = function( ol.format.EsriJSON.prototype.readGeometryFromObject = function(
object, opt_options) { object, opt_options) {
return ol.format.EsriJSON.readGeometry_( return ol.format.EsriJSON.readGeometry_(
/** @type {EsriJSONGeometry} */ (object), opt_options); /** @type {EsriJSONGeometry} */(object), opt_options);
}; };
@@ -560,7 +560,7 @@ ol.format.EsriJSON.prototype.readProjectionFromObject = function(object) {
*/ */
ol.format.EsriJSON.writeGeometry_ = function(geometry, opt_options) { ol.format.EsriJSON.writeGeometry_ = function(geometry, opt_options) {
var geometryWriter = ol.format.EsriJSON.GEOMETRY_WRITERS_[geometry.getType()]; var geometryWriter = ol.format.EsriJSON.GEOMETRY_WRITERS_[geometry.getType()];
return geometryWriter(/** @type {ol.geom.Geometry} */ ( return geometryWriter(/** @type {ol.geom.Geometry} */(
ol.format.Feature.transformWithOptions(geometry, true, opt_options)), ol.format.Feature.transformWithOptions(geometry, true, opt_options)),
opt_options); opt_options);
}; };
@@ -623,6 +623,12 @@ ol.format.EsriJSON.prototype.writeFeatureObject = function(
if (geometry) { if (geometry) {
object['geometry'] = object['geometry'] =
ol.format.EsriJSON.writeGeometry_(geometry, opt_options); ol.format.EsriJSON.writeGeometry_(geometry, opt_options);
if (opt_options && opt_options.featureProjection) {
object['geometry']['spatialReference'] = /** @type {EsriJSONCRS} */({
wkid: ol.proj.get(
opt_options.featureProjection).getCode().split(':').pop()
});
}
} }
var properties = feature.getProperties(); var properties = feature.getProperties();
delete properties[feature.getGeometryName()]; delete properties[feature.getGeometryName()];
@@ -631,12 +637,6 @@ ol.format.EsriJSON.prototype.writeFeatureObject = function(
} else { } else {
object['attributes'] = {}; object['attributes'] = {};
} }
if (opt_options && opt_options.featureProjection) {
object['spatialReference'] = /** @type {EsriJSONCRS} */({
wkid: ol.proj.get(
opt_options.featureProjection).getCode().split(':').pop()
});
}
return object; return object;
}; };