Move examples to examples directory
This commit is contained in:
20
examples/vector-esri-edit.html
Normal file
20
examples/vector-esri-edit.html
Normal file
@@ -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>
|
||||
151
examples/vector-esri-edit.js
Normal file
151
examples/vector-esri-edit.js
Normal file
@@ -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
|
||||
})
|
||||
});
|
||||
18
examples/vector-esri.html
Normal file
18
examples/vector-esri.html
Normal file
@@ -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>
|
||||
154
examples/vector-esri.js
Normal file
154
examples/vector-esri.js
Normal file
@@ -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);
|
||||
});
|
||||
Reference in New Issue
Block a user