@@ -309,6 +309,7 @@ def examples_star_json(name, match):
|
|||||||
"externs/bingmaps.js",
|
"externs/bingmaps.js",
|
||||||
"externs/bootstrap.js",
|
"externs/bootstrap.js",
|
||||||
"externs/closure-compiler.js",
|
"externs/closure-compiler.js",
|
||||||
|
"externs/esrijson.js",
|
||||||
"externs/example.js",
|
"externs/example.js",
|
||||||
"externs/fastclick.js",
|
"externs/fastclick.js",
|
||||||
"externs/geojson.js",
|
"externs/geojson.js",
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
"externs/bingmaps.js",
|
"externs/bingmaps.js",
|
||||||
"externs/bootstrap.js",
|
"externs/bootstrap.js",
|
||||||
"externs/closure-compiler.js",
|
"externs/closure-compiler.js",
|
||||||
|
"externs/esrijson.js",
|
||||||
"externs/example.js",
|
"externs/example.js",
|
||||||
"externs/fastclick.js",
|
"externs/fastclick.js",
|
||||||
"externs/geojson.js",
|
"externs/geojson.js",
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
"externs": [
|
"externs": [
|
||||||
"externs/bingmaps.js",
|
"externs/bingmaps.js",
|
||||||
"externs/closure-compiler.js",
|
"externs/closure-compiler.js",
|
||||||
|
"externs/esrijson.js",
|
||||||
"externs/geojson.js",
|
"externs/geojson.js",
|
||||||
"externs/oli.js",
|
"externs/oli.js",
|
||||||
"externs/olx.js",
|
"externs/olx.js",
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
template: example.html
|
||||||
|
title: esri ArcGIS REST Feature Service example with editing
|
||||||
|
shortdesc: Example of using an ArcGIS REST Feature Service in an editing application.
|
||||||
|
docs: >
|
||||||
|
This example loads features from ArcGIS REST Feature Service and allows to add new features or update existing features.
|
||||||
|
tags: "vector, esri, ArcGIS, REST, Feature, Service, bbox, loading, server, edit, updateFeature, addFeature"
|
||||||
|
---
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span12">
|
||||||
|
<div id="map" class="map"></div>
|
||||||
|
<form class="form-inline">
|
||||||
|
<label>Draw or modify </label>
|
||||||
|
<select id="type">
|
||||||
|
<option value="DRAW">Draw</option>
|
||||||
|
<option value="MODIFY">Modify</option>
|
||||||
|
</select>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,151 @@
|
|||||||
|
goog.require('ol.Attribution');
|
||||||
|
goog.require('ol.Map');
|
||||||
|
goog.require('ol.View');
|
||||||
|
goog.require('ol.format.EsriJSON');
|
||||||
|
goog.require('ol.interaction');
|
||||||
|
goog.require('ol.interaction.Draw');
|
||||||
|
goog.require('ol.interaction.Modify');
|
||||||
|
goog.require('ol.interaction.Select');
|
||||||
|
goog.require('ol.layer.Tile');
|
||||||
|
goog.require('ol.layer.Vector');
|
||||||
|
goog.require('ol.loadingstrategy');
|
||||||
|
goog.require('ol.proj');
|
||||||
|
goog.require('ol.source.Vector');
|
||||||
|
goog.require('ol.source.XYZ');
|
||||||
|
goog.require('ol.tilegrid.XYZ');
|
||||||
|
|
||||||
|
|
||||||
|
var serviceUrl = 'http://services.arcgis.com/rOo16HdIMeOBI4Mb/arcgis/rest/' +
|
||||||
|
'services/PDX_Pedestrian_Districts/FeatureServer/';
|
||||||
|
var layer = '0';
|
||||||
|
|
||||||
|
var esrijsonFormat = new ol.format.EsriJSON();
|
||||||
|
|
||||||
|
var vectorSource = new ol.source.Vector({
|
||||||
|
loader: function(extent, resolution, projection) {
|
||||||
|
var url = serviceUrl + layer + '/query/?f=json&' +
|
||||||
|
'returnGeometry=true&spatialRel=esriSpatialRelIntersects&geometry=' +
|
||||||
|
encodeURIComponent('{"xmin":' + extent[0] + ',"ymin":' +
|
||||||
|
extent[1] + ',"xmax":' + extent[2] + ',"ymax":' + extent[3] +
|
||||||
|
',"spatialReference":{"wkid":102100}}') +
|
||||||
|
'&geometryType=esriGeometryEnvelope&inSR=102100&outFields=*' +
|
||||||
|
'&outSR=102100';
|
||||||
|
$.ajax({url: url, dataType: 'jsonp', success: function(response) {
|
||||||
|
// dataProjection will be read from document
|
||||||
|
var features = esrijsonFormat.readFeatures(response, {
|
||||||
|
featureProjection: projection
|
||||||
|
});
|
||||||
|
if (features.length > 0) {
|
||||||
|
vectorSource.addFeatures(features);
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
},
|
||||||
|
strategy: ol.loadingstrategy.tile(new ol.tilegrid.XYZ({
|
||||||
|
tileSize: 512
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
|
||||||
|
var vector = new ol.layer.Vector({
|
||||||
|
source: vectorSource
|
||||||
|
});
|
||||||
|
|
||||||
|
var draw = new ol.interaction.Draw({
|
||||||
|
source: vectorSource,
|
||||||
|
type: /** @type {ol.geom.GeometryType} */ ('Polygon')
|
||||||
|
});
|
||||||
|
|
||||||
|
var select = new ol.interaction.Select();
|
||||||
|
select.setActive(false);
|
||||||
|
var selected = select.getFeatures();
|
||||||
|
|
||||||
|
var modify = new ol.interaction.Modify({
|
||||||
|
features: selected
|
||||||
|
});
|
||||||
|
modify.setActive(false);
|
||||||
|
|
||||||
|
var typeSelect = document.getElementById('type');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Let user change the interaction type.
|
||||||
|
* @param {Event} e Change event.
|
||||||
|
*/
|
||||||
|
typeSelect.onchange = function(e) {
|
||||||
|
draw.setActive(typeSelect.value === 'DRAW');
|
||||||
|
select.setActive(typeSelect.value === 'MODIFY');
|
||||||
|
modify.setActive(typeSelect.value === 'MODIFY');
|
||||||
|
};
|
||||||
|
|
||||||
|
var dirty = {};
|
||||||
|
|
||||||
|
selected.on('add', function(evt) {
|
||||||
|
var feature = evt.element;
|
||||||
|
feature.on('change', function(evt) {
|
||||||
|
dirty[evt.target.getId()] = true;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
selected.on('remove', function(evt) {
|
||||||
|
var feature = evt.element;
|
||||||
|
var fid = feature.getId();
|
||||||
|
if (dirty[fid] === true) {
|
||||||
|
var payload = '[' + esrijsonFormat.writeFeature(feature, {
|
||||||
|
featureProjection: select.getMap().getView().getProjection()
|
||||||
|
}) + ']';
|
||||||
|
var url = serviceUrl + layer + '/updateFeatures';
|
||||||
|
$.post(url, { f: 'json', features: payload }).done(function(data) {
|
||||||
|
var result = JSON.parse(data);
|
||||||
|
if (result.updateResults && result.updateResults.length > 0) {
|
||||||
|
if (result.updateResults[0].success !== true) {
|
||||||
|
var error = result.updateResults[0].error;
|
||||||
|
alert(error.description + ' (' + error.code + ')');
|
||||||
|
} else {
|
||||||
|
delete dirty[fid];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
draw.on('drawend', function(evt) {
|
||||||
|
var feature = evt.feature;
|
||||||
|
var payload = '[' + esrijsonFormat.writeFeature(feature, {
|
||||||
|
featureProjection: evt.target.getMap().getView().getProjection()
|
||||||
|
}) + ']';
|
||||||
|
var url = serviceUrl + layer + '/addFeatures';
|
||||||
|
$.post(url, { f: 'json', features: payload }).done(function(data) {
|
||||||
|
var result = JSON.parse(data);
|
||||||
|
if (result.addResults && result.addResults.length > 0) {
|
||||||
|
if (result.addResults[0].success === true) {
|
||||||
|
feature.setId(result.addResults[0]['objectId']);
|
||||||
|
vectorSource.clear();
|
||||||
|
} else {
|
||||||
|
var error = result.addResults[0].error;
|
||||||
|
alert(error.description + ' (' + error.code + ')');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var attribution = new ol.Attribution({
|
||||||
|
html: 'Tiles © <a href="http://services.arcgisonline.com/ArcGIS/' +
|
||||||
|
'rest/services/World_Topo_Map/MapServer">ArcGIS</a>'
|
||||||
|
});
|
||||||
|
|
||||||
|
var raster = new ol.layer.Tile({
|
||||||
|
source: new ol.source.XYZ({
|
||||||
|
attributions: [attribution],
|
||||||
|
url: 'http://server.arcgisonline.com/ArcGIS/rest/services/' +
|
||||||
|
'World_Topo_Map/MapServer/tile/{z}/{y}/{x}'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
var map = new ol.Map({
|
||||||
|
interactions: ol.interaction.defaults().extend([draw, select, modify]),
|
||||||
|
layers: [raster, vector],
|
||||||
|
target: document.getElementById('map'),
|
||||||
|
view: new ol.View({
|
||||||
|
center: ol.proj.transform([-122.619, 45.512], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
zoom: 12
|
||||||
|
})
|
||||||
|
});
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
---
|
||||||
|
template: example.html
|
||||||
|
title: esri ArcGIS REST Feature Service example
|
||||||
|
shortdesc: Example of using an ArcGIS REST Feature Service with a BBOX strategy.
|
||||||
|
docs: >
|
||||||
|
This example loads new features from ArcGIS REST Feature Service when the view extent changes.
|
||||||
|
tags: "vector, esri, ArcGIS, REST, Feature, Service, bbox, loading, server"
|
||||||
|
---
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span12">
|
||||||
|
<div id="map" class="map"></div>
|
||||||
|
<div class="span4 offset4 pull-right">
|
||||||
|
<div id="info" class="alert alert-success">
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -0,0 +1,154 @@
|
|||||||
|
goog.require('ol.Attribution');
|
||||||
|
goog.require('ol.Map');
|
||||||
|
goog.require('ol.View');
|
||||||
|
goog.require('ol.format.EsriJSON');
|
||||||
|
goog.require('ol.layer.Tile');
|
||||||
|
goog.require('ol.layer.Vector');
|
||||||
|
goog.require('ol.loadingstrategy');
|
||||||
|
goog.require('ol.proj');
|
||||||
|
goog.require('ol.source.Vector');
|
||||||
|
goog.require('ol.source.XYZ');
|
||||||
|
goog.require('ol.style.Fill');
|
||||||
|
goog.require('ol.style.Stroke');
|
||||||
|
goog.require('ol.style.Style');
|
||||||
|
goog.require('ol.tilegrid.XYZ');
|
||||||
|
|
||||||
|
|
||||||
|
var serviceUrl = 'http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/' +
|
||||||
|
'Petroleum/KSFields/FeatureServer/';
|
||||||
|
var layer = '0';
|
||||||
|
|
||||||
|
var esrijsonFormat = new ol.format.EsriJSON();
|
||||||
|
|
||||||
|
var styleCache = {
|
||||||
|
'ABANDONED': [
|
||||||
|
new ol.style.Style({
|
||||||
|
fill: new ol.style.Fill({
|
||||||
|
color: 'rgba(225, 225, 225, 255)'
|
||||||
|
}),
|
||||||
|
stroke: new ol.style.Stroke({
|
||||||
|
color: 'rgba(0, 0, 0, 255)',
|
||||||
|
width: 0.4
|
||||||
|
})
|
||||||
|
})
|
||||||
|
],
|
||||||
|
'GAS': [
|
||||||
|
new ol.style.Style({
|
||||||
|
fill: new ol.style.Fill({
|
||||||
|
color: 'rgba(255, 0, 0, 255)'
|
||||||
|
}),
|
||||||
|
stroke: new ol.style.Stroke({
|
||||||
|
color: 'rgba(110, 110, 110, 255)',
|
||||||
|
width: 0.4
|
||||||
|
})
|
||||||
|
})
|
||||||
|
],
|
||||||
|
'OIL': [
|
||||||
|
new ol.style.Style({
|
||||||
|
fill: new ol.style.Fill({
|
||||||
|
color: 'rgba(56, 168, 0, 255)'
|
||||||
|
}),
|
||||||
|
stroke: new ol.style.Stroke({
|
||||||
|
color: 'rgba(110, 110, 110, 255)',
|
||||||
|
width: 0
|
||||||
|
})
|
||||||
|
})
|
||||||
|
],
|
||||||
|
'OILGAS': [
|
||||||
|
new ol.style.Style({
|
||||||
|
fill: new ol.style.Fill({
|
||||||
|
color: 'rgba(168, 112, 0, 255)'
|
||||||
|
}),
|
||||||
|
stroke: new ol.style.Stroke({
|
||||||
|
color: 'rgba(110, 110, 110, 255)',
|
||||||
|
width: 0.4
|
||||||
|
})
|
||||||
|
})
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
var vectorSource = new ol.source.Vector({
|
||||||
|
loader: function(extent, resolution, projection) {
|
||||||
|
var url = serviceUrl + layer + '/query/?f=json&' +
|
||||||
|
'returnGeometry=true&spatialRel=esriSpatialRelIntersects&geometry=' +
|
||||||
|
encodeURIComponent('{"xmin":' + extent[0] + ',"ymin":' +
|
||||||
|
extent[1] + ',"xmax":' + extent[2] + ',"ymax":' + extent[3] +
|
||||||
|
',"spatialReference":{"wkid":102100}}') +
|
||||||
|
'&geometryType=esriGeometryEnvelope&inSR=102100&outFields=*' +
|
||||||
|
'&outSR=102100';
|
||||||
|
$.ajax({url: url, dataType: 'jsonp', success: function(response) {
|
||||||
|
// dataProjection will be read from document
|
||||||
|
var features = esrijsonFormat.readFeatures(response, {
|
||||||
|
featureProjection: projection
|
||||||
|
});
|
||||||
|
if (features.length > 0) {
|
||||||
|
vectorSource.addFeatures(features);
|
||||||
|
}
|
||||||
|
}});
|
||||||
|
},
|
||||||
|
strategy: ol.loadingstrategy.tile(new ol.tilegrid.XYZ({
|
||||||
|
tileSize: 512
|
||||||
|
}))
|
||||||
|
});
|
||||||
|
|
||||||
|
var vector = new ol.layer.Vector({
|
||||||
|
source: vectorSource,
|
||||||
|
style: function(feature, resolution) {
|
||||||
|
var classify = feature.get('activeprod');
|
||||||
|
return styleCache[classify];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var attribution = new ol.Attribution({
|
||||||
|
html: 'Tiles © <a href="http://services.arcgisonline.com/ArcGIS/' +
|
||||||
|
'rest/services/World_Topo_Map/MapServer">ArcGIS</a>'
|
||||||
|
});
|
||||||
|
|
||||||
|
var raster = new ol.layer.Tile({
|
||||||
|
source: new ol.source.XYZ({
|
||||||
|
attributions: [attribution],
|
||||||
|
url: 'http://server.arcgisonline.com/ArcGIS/rest/services/' +
|
||||||
|
'World_Topo_Map/MapServer/tile/{z}/{y}/{x}'
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
var map = new ol.Map({
|
||||||
|
layers: [raster, vector],
|
||||||
|
target: document.getElementById('map'),
|
||||||
|
view: new ol.View({
|
||||||
|
center: ol.proj.transform([-97.6114, 38.8403], 'EPSG:4326', 'EPSG:3857'),
|
||||||
|
zoom: 7
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
var displayFeatureInfo = function(pixel) {
|
||||||
|
var features = [];
|
||||||
|
map.forEachFeatureAtPixel(pixel, function(feature, layer) {
|
||||||
|
features.push(feature);
|
||||||
|
});
|
||||||
|
if (features.length > 0) {
|
||||||
|
var info = [];
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = features.length; i < ii; ++i) {
|
||||||
|
info.push(features[i].get('field_name'));
|
||||||
|
}
|
||||||
|
document.getElementById('info').innerHTML = info.join(', ') || '(unknown)';
|
||||||
|
map.getTarget().style.cursor = 'pointer';
|
||||||
|
} else {
|
||||||
|
document.getElementById('info').innerHTML = ' ';
|
||||||
|
map.getTarget().style.cursor = '';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
map.on('pointermove', function(evt) {
|
||||||
|
if (evt.dragging) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var pixel = map.getEventPixel(evt.originalEvent);
|
||||||
|
displayFeatureInfo(pixel);
|
||||||
|
});
|
||||||
|
|
||||||
|
map.on('click', function(evt) {
|
||||||
|
displayFeatureInfo(evt.pixel);
|
||||||
|
});
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* @fileoverview Externs for EsriJSON.
|
||||||
|
* @see http://resources.arcgis.com/en/help/rest/apiref/geometry.html
|
||||||
|
* @externs
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
var EsriJSONObject = function() {};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {!EsriJSONCRS}
|
||||||
|
*/
|
||||||
|
EsriJSONObject.prototype.spatialReference;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
var EsriJSONCRS = function() {};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CRS well know identifier.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
EsriJSONCRS.prototype.wkid;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {EsriJSONObject}
|
||||||
|
*/
|
||||||
|
var EsriJSONPoint = function() {};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* M value of point.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
EsriJSONPoint.prototype.m;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* X coordinate of point.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
EsriJSONPoint.prototype.x;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Y coordinate of point.
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
EsriJSONPoint.prototype.y;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Z coordinate of point.
|
||||||
|
* @type {number|undefined}
|
||||||
|
*/
|
||||||
|
EsriJSONPoint.prototype.z;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {EsriJSONObject}
|
||||||
|
*/
|
||||||
|
var EsriJSONMultipoint = function() {};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does Multipoint have M values?
|
||||||
|
* @type {boolean|undefined}
|
||||||
|
*/
|
||||||
|
EsriJSONMultipoint.prototype.hasM;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does Multipoint have Z values?
|
||||||
|
* @type {boolean|undefined}
|
||||||
|
*/
|
||||||
|
EsriJSONMultipoint.prototype.hasZ;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {!Array.<!Array.<number>>}
|
||||||
|
*/
|
||||||
|
EsriJSONMultipoint.prototype.points;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {EsriJSONObject}
|
||||||
|
*/
|
||||||
|
var EsriJSONPolyline = function() {};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does Polyline have M values?
|
||||||
|
* @type {boolean|undefined}
|
||||||
|
*/
|
||||||
|
EsriJSONPolyline.prototype.hasM;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does Polyline have Z values?
|
||||||
|
* @type {boolean|undefined}
|
||||||
|
*/
|
||||||
|
EsriJSONPolyline.prototype.hasZ;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {!Array.<!Array.<!Array.<number>>>}
|
||||||
|
*/
|
||||||
|
EsriJSONPolyline.prototype.paths;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {EsriJSONObject}
|
||||||
|
*/
|
||||||
|
var EsriJSONPolygon = function() {};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does Polygon have M values?
|
||||||
|
* @type {boolean|undefined}
|
||||||
|
*/
|
||||||
|
EsriJSONPolygon.prototype.hasM;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does Polygon have Z values?
|
||||||
|
* @type {boolean|undefined}
|
||||||
|
*/
|
||||||
|
EsriJSONPolygon.prototype.hasZ;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {!Array.<!Array.<!Array.<number>>>}
|
||||||
|
*/
|
||||||
|
EsriJSONPolygon.prototype.rings;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {(EsriJSONPoint|EsriJSONMultipoint|EsriJSONPolyline|
|
||||||
|
EsriJSONPolygon)}
|
||||||
|
*/
|
||||||
|
var EsriJSONGeometry;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {EsriJSONObject}
|
||||||
|
*/
|
||||||
|
var EsriJSONFeature = function() {};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {EsriJSONGeometry}
|
||||||
|
*/
|
||||||
|
EsriJSONFeature.prototype.geometry;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {Object.<string, *>}
|
||||||
|
*/
|
||||||
|
EsriJSONFeature.prototype.attributes;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constructor
|
||||||
|
* @extends {EsriJSONObject}
|
||||||
|
*/
|
||||||
|
var EsriJSONFeatureCollection = function() {};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {!Array.<EsriJSONFeature>}
|
||||||
|
*/
|
||||||
|
EsriJSONFeatureCollection.prototype.features;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the attribute that contains ids.
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
EsriJSONFeatureCollection.prototype.objectIdFieldName;
|
||||||
@@ -1635,6 +1635,21 @@ olx.format.GeoJSONOptions.prototype.defaultDataProjection;
|
|||||||
olx.format.GeoJSONOptions.prototype.geometryName;
|
olx.format.GeoJSONOptions.prototype.geometryName;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @typedef {{geometryName: (string|undefined)}}
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
olx.format.EsriJSONOptions;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Geometry name to use when creating features.
|
||||||
|
* @type {string|undefined}
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
olx.format.EsriJSONOptions.prototype.geometryName;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {{factor: (number|undefined),
|
* @typedef {{factor: (number|undefined),
|
||||||
* geometryLayout: (ol.geom.GeometryLayout|undefined)}}
|
* geometryLayout: (ol.geom.GeometryLayout|undefined)}}
|
||||||
|
|||||||
@@ -0,0 +1,706 @@
|
|||||||
|
goog.provide('ol.format.EsriJSON');
|
||||||
|
|
||||||
|
goog.require('goog.array');
|
||||||
|
goog.require('goog.asserts');
|
||||||
|
goog.require('goog.object');
|
||||||
|
goog.require('ol.Feature');
|
||||||
|
goog.require('ol.extent');
|
||||||
|
goog.require('ol.format.Feature');
|
||||||
|
goog.require('ol.format.JSONFeature');
|
||||||
|
goog.require('ol.geom.GeometryLayout');
|
||||||
|
goog.require('ol.geom.GeometryType');
|
||||||
|
goog.require('ol.geom.LineString');
|
||||||
|
goog.require('ol.geom.LinearRing');
|
||||||
|
goog.require('ol.geom.MultiLineString');
|
||||||
|
goog.require('ol.geom.MultiPoint');
|
||||||
|
goog.require('ol.geom.MultiPolygon');
|
||||||
|
goog.require('ol.geom.Point');
|
||||||
|
goog.require('ol.geom.Polygon');
|
||||||
|
goog.require('ol.geom.flat.orient');
|
||||||
|
goog.require('ol.proj');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @classdesc
|
||||||
|
* Feature format for reading and writing data in the EsriJSON format.
|
||||||
|
*
|
||||||
|
* @constructor
|
||||||
|
* @extends {ol.format.JSONFeature}
|
||||||
|
* @param {olx.format.EsriJSONOptions=} opt_options Options.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON = function(opt_options) {
|
||||||
|
|
||||||
|
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||||
|
|
||||||
|
goog.base(this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the geometry attribute for features.
|
||||||
|
* @type {string|undefined}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this.geometryName_ = options.geometryName;
|
||||||
|
|
||||||
|
};
|
||||||
|
goog.inherits(ol.format.EsriJSON, ol.format.JSONFeature);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {EsriJSONGeometry} object Object.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
|
* @private
|
||||||
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.readGeometry_ = function(object, opt_options) {
|
||||||
|
if (goog.isNull(object)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var type;
|
||||||
|
if (goog.isNumber(object.x) && goog.isNumber(object.y)) {
|
||||||
|
type = ol.geom.GeometryType.POINT;
|
||||||
|
} else if (goog.isDefAndNotNull(object.points)) {
|
||||||
|
type = ol.geom.GeometryType.MULTI_POINT;
|
||||||
|
} else if (goog.isDefAndNotNull(object.paths)) {
|
||||||
|
if (object.paths.length === 1) {
|
||||||
|
type = ol.geom.GeometryType.LINE_STRING;
|
||||||
|
} else {
|
||||||
|
type = ol.geom.GeometryType.MULTI_LINE_STRING;
|
||||||
|
}
|
||||||
|
} else if (goog.isDefAndNotNull(object.rings)) {
|
||||||
|
var layout = ol.format.EsriJSON.getGeometryLayout_(object);
|
||||||
|
var rings = ol.format.EsriJSON.convertRings_(object.rings, layout);
|
||||||
|
object = /** @type {EsriJSONGeometry} */(goog.object.clone(object));
|
||||||
|
if (rings.length === 1) {
|
||||||
|
type = ol.geom.GeometryType.POLYGON;
|
||||||
|
object.rings = rings[0];
|
||||||
|
} else {
|
||||||
|
type = ol.geom.GeometryType.MULTI_POLYGON;
|
||||||
|
object.rings = rings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
goog.asserts.assert(goog.isDef(type), 'geometry type should be defined');
|
||||||
|
var geometryReader = ol.format.EsriJSON.GEOMETRY_READERS_[type];
|
||||||
|
goog.asserts.assert(goog.isDef(geometryReader),
|
||||||
|
'geometryReader should be defined');
|
||||||
|
return /** @type {ol.geom.Geometry} */ (
|
||||||
|
ol.format.Feature.transformWithOptions(
|
||||||
|
geometryReader(object), false, opt_options));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines inner and outer rings.
|
||||||
|
* Checks if any polygons in this array contain any other polygons in this
|
||||||
|
* array. It is used for checking for holes.
|
||||||
|
* Logic inspired by: https://github.com/Esri/terraformer-arcgis-parser
|
||||||
|
* @param {Array.<!Array.<!Array.<number>>>} rings Rings.
|
||||||
|
* @param {ol.geom.GeometryLayout} layout Geometry layout.
|
||||||
|
* @private
|
||||||
|
* @return {Array.<!Array.<!Array.<number>>>} Transoformed rings.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.convertRings_ = function(rings, layout) {
|
||||||
|
var outerRings = [];
|
||||||
|
var holes = [];
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = rings.length; i < ii; ++i) {
|
||||||
|
var flatRing = goog.array.flatten(rings[i]);
|
||||||
|
// is this ring an outer ring? is it clockwise?
|
||||||
|
var clockwise = ol.geom.flat.orient.linearRingIsClockwise(flatRing, 0,
|
||||||
|
flatRing.length, layout.length);
|
||||||
|
if (clockwise) {
|
||||||
|
outerRings.push([rings[i]]);
|
||||||
|
} else {
|
||||||
|
holes.push(rings[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (holes.length) {
|
||||||
|
var hole = holes.shift();
|
||||||
|
var matched = false;
|
||||||
|
// loop over all outer rings and see if they contain our hole.
|
||||||
|
for (i = outerRings.length - 1; i >= 0; i--) {
|
||||||
|
var outerRing = outerRings[i][0];
|
||||||
|
if (ol.extent.containsExtent(new ol.geom.LinearRing(
|
||||||
|
outerRing).getExtent(),
|
||||||
|
new ol.geom.LinearRing(hole).getExtent())) {
|
||||||
|
// the hole is contained push it into our polygon
|
||||||
|
outerRings[i].push(hole);
|
||||||
|
matched = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!matched) {
|
||||||
|
// no outer rings contain this hole turn it into and outer
|
||||||
|
// ring (reverse it)
|
||||||
|
outerRings.push([hole.reverse()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return outerRings;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {EsriJSONGeometry} object Object.
|
||||||
|
* @private
|
||||||
|
* @return {ol.geom.Geometry} Point.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.readPointGeometry_ = function(object) {
|
||||||
|
goog.asserts.assert(goog.isNumber(object.x), 'object.x should be number');
|
||||||
|
goog.asserts.assert(goog.isNumber(object.y), 'object.y should be number');
|
||||||
|
var point;
|
||||||
|
if (goog.isDefAndNotNull(object.m) && goog.isDefAndNotNull(object.z)) {
|
||||||
|
point = new ol.geom.Point([object.x, object.y, object.z, object.m],
|
||||||
|
ol.geom.GeometryLayout.XYZM);
|
||||||
|
} else if (goog.isDefAndNotNull(object.z)) {
|
||||||
|
point = new ol.geom.Point([object.x, object.y, object.z],
|
||||||
|
ol.geom.GeometryLayout.XYZ);
|
||||||
|
} else if (goog.isDefAndNotNull(object.m)) {
|
||||||
|
point = new ol.geom.Point([object.x, object.y, object.m],
|
||||||
|
ol.geom.GeometryLayout.XYM);
|
||||||
|
} else {
|
||||||
|
point = new ol.geom.Point([object.x, object.y]);
|
||||||
|
}
|
||||||
|
return point;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {EsriJSONGeometry} object Object.
|
||||||
|
* @private
|
||||||
|
* @return {ol.geom.Geometry} LineString.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.readLineStringGeometry_ = function(object) {
|
||||||
|
goog.asserts.assert(goog.isArray(object.paths),
|
||||||
|
'object.paths should be an array');
|
||||||
|
goog.asserts.assert(object.paths.length === 1,
|
||||||
|
'object.paths array length should be 1');
|
||||||
|
var layout = ol.format.EsriJSON.getGeometryLayout_(object);
|
||||||
|
return new ol.geom.LineString(object.paths[0], layout);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {EsriJSONGeometry} object Object.
|
||||||
|
* @private
|
||||||
|
* @return {ol.geom.Geometry} MultiLineString.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.readMultiLineStringGeometry_ = function(object) {
|
||||||
|
goog.asserts.assert(goog.isArray(object.paths),
|
||||||
|
'object.paths should be an array');
|
||||||
|
goog.asserts.assert(object.paths.length > 1,
|
||||||
|
'object.paths array length should be more than 1');
|
||||||
|
var layout = ol.format.EsriJSON.getGeometryLayout_(object);
|
||||||
|
return new ol.geom.MultiLineString(object.paths, layout);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {EsriJSONGeometry} object Object.
|
||||||
|
* @private
|
||||||
|
* @return {ol.geom.GeometryLayout} The geometry layout to use.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.getGeometryLayout_ = function(object) {
|
||||||
|
var layout = ol.geom.GeometryLayout.XY;
|
||||||
|
if (object.hasZ === true && object.hasM === true) {
|
||||||
|
layout = ol.geom.GeometryLayout.XYZM;
|
||||||
|
} else if (object.hasZ === true) {
|
||||||
|
layout = ol.geom.GeometryLayout.XYZ;
|
||||||
|
} else if (object.hasM === true) {
|
||||||
|
layout = ol.geom.GeometryLayout.XYM;
|
||||||
|
}
|
||||||
|
return layout;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {EsriJSONGeometry} object Object.
|
||||||
|
* @private
|
||||||
|
* @return {ol.geom.Geometry} MultiPoint.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.readMultiPointGeometry_ = function(object) {
|
||||||
|
goog.asserts.assert(goog.isDefAndNotNull(object.points),
|
||||||
|
'object.points should be defined');
|
||||||
|
var layout = ol.format.EsriJSON.getGeometryLayout_(object);
|
||||||
|
return new ol.geom.MultiPoint(object.points, layout);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {EsriJSONGeometry} object Object.
|
||||||
|
* @private
|
||||||
|
* @return {ol.geom.Geometry} MultiPolygon.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.readMultiPolygonGeometry_ = function(object) {
|
||||||
|
goog.asserts.assert(goog.isDefAndNotNull(object.rings));
|
||||||
|
goog.asserts.assert(object.rings.length > 1,
|
||||||
|
'object.rings should have length larger than 1');
|
||||||
|
var layout = ol.format.EsriJSON.getGeometryLayout_(object);
|
||||||
|
return new ol.geom.MultiPolygon(
|
||||||
|
/** @type {Array.<Array.<Array.<Array.<number>>>>} */(object.rings),
|
||||||
|
layout);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {EsriJSONGeometry} object Object.
|
||||||
|
* @private
|
||||||
|
* @return {ol.geom.Geometry} Polygon.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.readPolygonGeometry_ = function(object) {
|
||||||
|
goog.asserts.assert(goog.isDefAndNotNull(object.rings));
|
||||||
|
var layout = ol.format.EsriJSON.getGeometryLayout_(object);
|
||||||
|
return new ol.geom.Polygon(object.rings, layout);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
|
* @private
|
||||||
|
* @return {EsriJSONGeometry} EsriJSON geometry.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.writePointGeometry_ = function(geometry, opt_options) {
|
||||||
|
goog.asserts.assertInstanceof(geometry, ol.geom.Point,
|
||||||
|
'geometry should be an ol.geom.Point');
|
||||||
|
var coordinates = geometry.getCoordinates();
|
||||||
|
var layout = geometry.getLayout();
|
||||||
|
if (layout === ol.geom.GeometryLayout.XYZ) {
|
||||||
|
return /** @type {EsriJSONPoint} */ ({
|
||||||
|
x: coordinates[0],
|
||||||
|
y: coordinates[1],
|
||||||
|
z: coordinates[2]
|
||||||
|
});
|
||||||
|
} else if (layout === ol.geom.GeometryLayout.XYM) {
|
||||||
|
return /** @type {EsriJSONPoint} */ ({
|
||||||
|
x: coordinates[0],
|
||||||
|
y: coordinates[1],
|
||||||
|
m: coordinates[2]
|
||||||
|
});
|
||||||
|
} else if (layout === ol.geom.GeometryLayout.XYZM) {
|
||||||
|
return /** @type {EsriJSONPoint} */ ({
|
||||||
|
x: coordinates[0],
|
||||||
|
y: coordinates[1],
|
||||||
|
z: coordinates[2],
|
||||||
|
m: coordinates[3]
|
||||||
|
});
|
||||||
|
} else if (layout === ol.geom.GeometryLayout.XY) {
|
||||||
|
return /** @type {EsriJSONPoint} */ ({
|
||||||
|
x: coordinates[0],
|
||||||
|
y: coordinates[1]
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
goog.asserts.fail('Unknown geometry layout');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.SimpleGeometry} geometry Geometry.
|
||||||
|
* @private
|
||||||
|
* @return {Object} Object with boolean hasZ and hasM keys.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.getHasZM_ = function(geometry) {
|
||||||
|
var layout = geometry.getLayout();
|
||||||
|
return {
|
||||||
|
hasZ: (layout === ol.geom.GeometryLayout.XYZ ||
|
||||||
|
layout === ol.geom.GeometryLayout.XYZM),
|
||||||
|
hasM: (layout === ol.geom.GeometryLayout.XYM ||
|
||||||
|
layout === ol.geom.GeometryLayout.XYZM)
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
|
* @private
|
||||||
|
* @return {EsriJSONPolyline} EsriJSON geometry.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.writeLineStringGeometry_ = function(geometry, opt_options) {
|
||||||
|
goog.asserts.assertInstanceof(geometry, ol.geom.LineString,
|
||||||
|
'geometry should be an ol.geom.LineString');
|
||||||
|
var hasZM = ol.format.EsriJSON.getHasZM_(geometry);
|
||||||
|
return /** @type {EsriJSONPolyline} */ ({
|
||||||
|
hasZ: hasZM.hasZ,
|
||||||
|
hasM: hasZM.hasM,
|
||||||
|
paths: [geometry.getCoordinates()]
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
|
* @private
|
||||||
|
* @return {EsriJSONPolygon} EsriJSON geometry.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.writePolygonGeometry_ = function(geometry, opt_options) {
|
||||||
|
goog.asserts.assertInstanceof(geometry, ol.geom.Polygon,
|
||||||
|
'geometry should be an ol.geom.Polygon');
|
||||||
|
// Esri geometries use the left-hand rule
|
||||||
|
var hasZM = ol.format.EsriJSON.getHasZM_(geometry);
|
||||||
|
return /** @type {EsriJSONPolygon} */ ({
|
||||||
|
hasZ: hasZM.hasZ,
|
||||||
|
hasM: hasZM.hasM,
|
||||||
|
rings: geometry.getCoordinates(false)
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
|
* @private
|
||||||
|
* @return {EsriJSONPolyline} EsriJSON geometry.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.writeMultiLineStringGeometry_ =
|
||||||
|
function(geometry, opt_options) {
|
||||||
|
goog.asserts.assertInstanceof(geometry, ol.geom.MultiLineString,
|
||||||
|
'geometry should be an ol.geom.MultiLineString');
|
||||||
|
var hasZM = ol.format.EsriJSON.getHasZM_(geometry);
|
||||||
|
return /** @type {EsriJSONPolyline} */ ({
|
||||||
|
hasZ: hasZM.hasZ,
|
||||||
|
hasM: hasZM.hasM,
|
||||||
|
paths: geometry.getCoordinates()
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
|
* @private
|
||||||
|
* @return {EsriJSONMultipoint} EsriJSON geometry.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.writeMultiPointGeometry_ = function(geometry, opt_options) {
|
||||||
|
goog.asserts.assertInstanceof(geometry, ol.geom.MultiPoint,
|
||||||
|
'geometry should be an ol.geom.MultiPoint');
|
||||||
|
var hasZM = ol.format.EsriJSON.getHasZM_(geometry);
|
||||||
|
return /** @type {EsriJSONMultipoint} */ ({
|
||||||
|
hasZ: hasZM.hasZ,
|
||||||
|
hasM: hasZM.hasM,
|
||||||
|
points: geometry.getCoordinates()
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
|
* @private
|
||||||
|
* @return {EsriJSONPolygon} EsriJSON geometry.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.writeMultiPolygonGeometry_ = function(geometry,
|
||||||
|
opt_options) {
|
||||||
|
goog.asserts.assertInstanceof(geometry, ol.geom.MultiPolygon,
|
||||||
|
'geometry should be an ol.geom.MultiPolygon');
|
||||||
|
var hasZM = ol.format.EsriJSON.getHasZM_(geometry);
|
||||||
|
var coordinates = geometry.getCoordinates(false);
|
||||||
|
var output = [];
|
||||||
|
for (var i = 0; i < coordinates.length; i++) {
|
||||||
|
for (var x = coordinates[i].length - 1; x >= 0; x--) {
|
||||||
|
output.push(coordinates[i][x]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return /** @type {EsriJSONPolygon} */ ({
|
||||||
|
hasZ: hasZM.hasZ,
|
||||||
|
hasM: hasZM.hasM,
|
||||||
|
rings: output
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @private
|
||||||
|
* @type {Object.<ol.geom.GeometryType, function(EsriJSONGeometry): ol.geom.Geometry>}
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.GEOMETRY_READERS_ = {};
|
||||||
|
ol.format.EsriJSON.GEOMETRY_READERS_[ol.geom.GeometryType.POINT] =
|
||||||
|
ol.format.EsriJSON.readPointGeometry_;
|
||||||
|
ol.format.EsriJSON.GEOMETRY_READERS_[ol.geom.GeometryType.LINE_STRING] =
|
||||||
|
ol.format.EsriJSON.readLineStringGeometry_;
|
||||||
|
ol.format.EsriJSON.GEOMETRY_READERS_[ol.geom.GeometryType.POLYGON] =
|
||||||
|
ol.format.EsriJSON.readPolygonGeometry_;
|
||||||
|
ol.format.EsriJSON.GEOMETRY_READERS_[ol.geom.GeometryType.MULTI_POINT] =
|
||||||
|
ol.format.EsriJSON.readMultiPointGeometry_;
|
||||||
|
ol.format.EsriJSON.GEOMETRY_READERS_[ol.geom.GeometryType.MULTI_LINE_STRING] =
|
||||||
|
ol.format.EsriJSON.readMultiLineStringGeometry_;
|
||||||
|
ol.format.EsriJSON.GEOMETRY_READERS_[ol.geom.GeometryType.MULTI_POLYGON] =
|
||||||
|
ol.format.EsriJSON.readMultiPolygonGeometry_;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @const
|
||||||
|
* @private
|
||||||
|
* @type {Object.<string, function(ol.geom.Geometry, olx.format.WriteOptions=): (EsriJSONGeometry)>}
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.GEOMETRY_WRITERS_ = {};
|
||||||
|
ol.format.EsriJSON.GEOMETRY_WRITERS_[ol.geom.GeometryType.POINT] =
|
||||||
|
ol.format.EsriJSON.writePointGeometry_;
|
||||||
|
ol.format.EsriJSON.GEOMETRY_WRITERS_[ol.geom.GeometryType.LINE_STRING] =
|
||||||
|
ol.format.EsriJSON.writeLineStringGeometry_;
|
||||||
|
ol.format.EsriJSON.GEOMETRY_WRITERS_[ol.geom.GeometryType.POLYGON] =
|
||||||
|
ol.format.EsriJSON.writePolygonGeometry_;
|
||||||
|
ol.format.EsriJSON.GEOMETRY_WRITERS_[ol.geom.GeometryType.MULTI_POINT] =
|
||||||
|
ol.format.EsriJSON.writeMultiPointGeometry_;
|
||||||
|
ol.format.EsriJSON.GEOMETRY_WRITERS_[ol.geom.GeometryType.MULTI_LINE_STRING] =
|
||||||
|
ol.format.EsriJSON.writeMultiLineStringGeometry_;
|
||||||
|
ol.format.EsriJSON.GEOMETRY_WRITERS_[ol.geom.GeometryType.MULTI_POLYGON] =
|
||||||
|
ol.format.EsriJSON.writeMultiPolygonGeometry_;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read a feature from a EsriJSON Feature source. Only works for Feature,
|
||||||
|
* use `readFeatures` to read FeatureCollection source.
|
||||||
|
*
|
||||||
|
* @function
|
||||||
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
|
* @return {ol.Feature} Feature.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.readFeature;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read all features from a EsriJSON source. Works with both Feature and
|
||||||
|
* FeatureCollection sources.
|
||||||
|
*
|
||||||
|
* @function
|
||||||
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
|
* @return {Array.<ol.Feature>} Features.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.readFeatures;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.readFeatureFromObject = function(
|
||||||
|
object, opt_options) {
|
||||||
|
var esriJSONFeature = /** @type {EsriJSONFeature} */ (object);
|
||||||
|
goog.asserts.assert(goog.isDefAndNotNull(esriJSONFeature.geometry) ||
|
||||||
|
goog.isDefAndNotNull(esriJSONFeature.compressedGeometry) ||
|
||||||
|
goog.isDefAndNotNull(esriJSONFeature.attributes),
|
||||||
|
'geometry, compressedGeometry or attributes should be defined');
|
||||||
|
var geometry = ol.format.EsriJSON.readGeometry_(esriJSONFeature.geometry,
|
||||||
|
opt_options);
|
||||||
|
var feature = new ol.Feature();
|
||||||
|
if (goog.isDef(this.geometryName_)) {
|
||||||
|
feature.setGeometryName(this.geometryName_);
|
||||||
|
}
|
||||||
|
feature.setGeometry(geometry);
|
||||||
|
if (goog.isDef(opt_options) && goog.isDef(opt_options.idField) &&
|
||||||
|
goog.isDef(esriJSONFeature.attributes[opt_options.idField])) {
|
||||||
|
goog.asserts.assert(
|
||||||
|
goog.isNumber(esriJSONFeature.attributes[opt_options.idField]),
|
||||||
|
'objectIdFieldName value should be a number');
|
||||||
|
feature.setId(/** @type {number} */(
|
||||||
|
esriJSONFeature.attributes[opt_options.idField]));
|
||||||
|
}
|
||||||
|
if (goog.isDef(esriJSONFeature.attributes)) {
|
||||||
|
feature.setProperties(esriJSONFeature.attributes);
|
||||||
|
}
|
||||||
|
return feature;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.readFeaturesFromObject = function(
|
||||||
|
object, opt_options) {
|
||||||
|
var esriJSONObject = /** @type {EsriJSONObject} */ (object);
|
||||||
|
var options = goog.isDef(opt_options) ? opt_options : {};
|
||||||
|
if (goog.isDefAndNotNull(esriJSONObject.features)) {
|
||||||
|
var esriJSONFeatureCollection = /** @type {EsriJSONFeatureCollection} */
|
||||||
|
(object);
|
||||||
|
/** @type {Array.<ol.Feature>} */
|
||||||
|
var features = [];
|
||||||
|
var esriJSONFeatures = esriJSONFeatureCollection.features;
|
||||||
|
var i, ii;
|
||||||
|
options.idField = object.objectIdFieldName;
|
||||||
|
for (i = 0, ii = esriJSONFeatures.length; i < ii; ++i) {
|
||||||
|
features.push(this.readFeatureFromObject(esriJSONFeatures[i],
|
||||||
|
options));
|
||||||
|
}
|
||||||
|
return features;
|
||||||
|
} else {
|
||||||
|
return [this.readFeatureFromObject(object, options)];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read a geometry from a EsriJSON source.
|
||||||
|
*
|
||||||
|
* @function
|
||||||
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @param {olx.format.ReadOptions=} opt_options Read options.
|
||||||
|
* @return {ol.geom.Geometry} Geometry.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.readGeometry;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.readGeometryFromObject = function(
|
||||||
|
object, opt_options) {
|
||||||
|
return ol.format.EsriJSON.readGeometry_(
|
||||||
|
/** @type {EsriJSONGeometry} */ (object), opt_options);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read the projection from a EsriJSON source.
|
||||||
|
*
|
||||||
|
* @function
|
||||||
|
* @param {ArrayBuffer|Document|Node|Object|string} source Source.
|
||||||
|
* @return {ol.proj.Projection} Projection.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.readProjection;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.readProjectionFromObject = function(object) {
|
||||||
|
var esriJSONObject = /** @type {EsriJSONObject} */ (object);
|
||||||
|
if (goog.isDefAndNotNull(esriJSONObject.spatialReference) &&
|
||||||
|
goog.isDefAndNotNull(esriJSONObject.spatialReference.wkid)) {
|
||||||
|
var crs = esriJSONObject.spatialReference.wkid;
|
||||||
|
return ol.proj.get('EPSG:' + crs);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
|
* @private
|
||||||
|
* @return {EsriJSONGeometry} EsriJSON geometry.
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.writeGeometry_ = function(geometry, opt_options) {
|
||||||
|
var geometryWriter = ol.format.EsriJSON.GEOMETRY_WRITERS_[geometry.getType()];
|
||||||
|
goog.asserts.assert(goog.isDef(geometryWriter),
|
||||||
|
'geometryWriter should be defined');
|
||||||
|
return geometryWriter(/** @type {ol.geom.Geometry} */ (
|
||||||
|
ol.format.Feature.transformWithOptions(geometry, true, opt_options)),
|
||||||
|
opt_options);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode a geometry as a EsriJSON string.
|
||||||
|
*
|
||||||
|
* @function
|
||||||
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
|
* @return {string} EsriJSON.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.writeGeometry;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode a geometry as a EsriJSON object.
|
||||||
|
*
|
||||||
|
* @param {ol.geom.Geometry} geometry Geometry.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
|
* @return {EsriJSONGeometry} Object.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.writeGeometryObject = function(geometry,
|
||||||
|
opt_options) {
|
||||||
|
return ol.format.EsriJSON.writeGeometry_(geometry,
|
||||||
|
this.adaptOptions(opt_options));
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode a feature as a EsriJSON Feature string.
|
||||||
|
*
|
||||||
|
* @function
|
||||||
|
* @param {ol.Feature} feature Feature.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
|
* @return {string} EsriJSON.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.writeFeature;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode a feature as a esriJSON Feature object.
|
||||||
|
*
|
||||||
|
* @param {ol.Feature} feature Feature.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
|
* @return {Object} Object.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.writeFeatureObject = function(
|
||||||
|
feature, opt_options) {
|
||||||
|
opt_options = this.adaptOptions(opt_options);
|
||||||
|
var object = {};
|
||||||
|
var geometry = feature.getGeometry();
|
||||||
|
if (goog.isDefAndNotNull(geometry)) {
|
||||||
|
object['geometry'] =
|
||||||
|
ol.format.EsriJSON.writeGeometry_(geometry, opt_options);
|
||||||
|
}
|
||||||
|
var properties = feature.getProperties();
|
||||||
|
goog.object.remove(properties, feature.getGeometryName());
|
||||||
|
if (!goog.object.isEmpty(properties)) {
|
||||||
|
object['attributes'] = properties;
|
||||||
|
} else {
|
||||||
|
object['attributes'] = {};
|
||||||
|
}
|
||||||
|
if (goog.isDef(opt_options) && goog.isDef(opt_options.featureProjection)) {
|
||||||
|
object['spatialReference'] = /** @type {EsriJSONCRS} */({
|
||||||
|
wkid: ol.proj.get(
|
||||||
|
opt_options.featureProjection).getCode().split(':').pop()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return object;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode an array of features as EsriJSON.
|
||||||
|
*
|
||||||
|
* @function
|
||||||
|
* @param {Array.<ol.Feature>} features Features.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
|
* @return {string} EsriJSON.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.writeFeatures;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode an array of features as a EsriJSON object.
|
||||||
|
*
|
||||||
|
* @param {Array.<ol.Feature>} features Features.
|
||||||
|
* @param {olx.format.WriteOptions=} opt_options Write options.
|
||||||
|
* @return {Object} EsriJSON Object.
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
ol.format.EsriJSON.prototype.writeFeaturesObject =
|
||||||
|
function(features, opt_options) {
|
||||||
|
opt_options = this.adaptOptions(opt_options);
|
||||||
|
var objects = [];
|
||||||
|
var i, ii;
|
||||||
|
for (i = 0, ii = features.length; i < ii; ++i) {
|
||||||
|
objects.push(this.writeFeatureObject(features[i], opt_options));
|
||||||
|
}
|
||||||
|
return /** @type {EsriJSONFeatureCollection} */ ({
|
||||||
|
'features': objects
|
||||||
|
});
|
||||||
|
};
|
||||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user