Skip to content
Browse files

Added sample that loads any feature service by REST endpoint

  • Loading branch information...
1 parent 43b218e commit 7d347f0de894131f0ee91faf5957b9b35f49cee6 @alaframboise alaframboise committed
Showing with 130 additions and 0 deletions.
  1. +1 −0 css/examples.css
  2. +128 −0 html/cloud/get_feature_service.html
  3. +1 −0 index.html
View
1 css/examples.css
@@ -612,6 +612,7 @@ input,
textarea,
.uneditable-input {
margin-left: 0;
+ margin-bottom: 4px;
}
input[disabled],
View
128 html/cloud/get_feature_service.html
@@ -0,0 +1,128 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">
+ <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
+ <title>Get Feature Service</title>
+ <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/js/esri/css/esri.css">
+ <link rel="stylesheet" href="../../css/examples.css">
+ <!-- Load the library references for ArcGIS API for JavaScript -->
+ <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3compact"></script>
+ <script>
+ dojo.require("esri.map");
+ dojo.require("esri.layers.graphics");
+ dojo.require("esri.layers.FeatureLayer");
+ dojo.require("esri.dijit.Popup");
+ dojo.require("esri.tasks.geometry");
+
+ var featureLayer, oldFeatureLayer;
+ var geometryService;
+
+ function init() {
+ var options = {
+ basemap: "gray",
+ center: [-28,40],
+ zoom: 3,
+ infoWindow: new esri.dijit.Popup(null, dojo.create("div")) // Define a popup
+ }
+ // Create map
+ map = new esri.Map("mapDiv", options);
+ geometryService = new esri.tasks.GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
+ // Zoom to layer
+ dojo.connect(map, "onLayerAddResult", layerAdded);
+ // Listen for map update events
+ dojo.connect(map,"onUpdateStart",function(){
+ setStyle("progress", "progress");
+ });
+ dojo.connect(map,"onUpdateEnd",function(){
+ setStyle("progress", "progress hidden");
+ });
+ }
+
+ // Listen for enter key
+ function addService_onKeyPress(e) {
+ if (e.keyCode == 13 || e.keyCode == "13") {
+ addFeatureService();
+ }
+ }
+
+ function addFeatureService() {
+ // Create a feature layer to get feature service
+ setStyle("progress", "progress");
+ removeFeatureService();
+ var infoTemplate = new esri.InfoTemplate("Fields", "");
+ var url = document.getElementById("featureServiceUrl").value.trim();
+ featureLayer = new esri.layers.FeatureLayer(url, {
+ mode: esri.layers.FeatureLayer.MODE_ONDEMAND,
+ outFields: ["*"],
+ opacity: .80,
+ infoTemplate: infoTemplate
+ });
+ map.addLayer(featureLayer);
+ }
+
+ function removeFeatureService() {
+ setStyle("progress", "progress hidden");
+ if (featureLayer) {
+ map.removeLayer(featureLayer);
+ map.infoWindow.hide();
+ }
+ }
+
+ function layerAdded(layer, error) {
+ if (featureLayer) {
+ if (typeof error == 'undefined') {
+ zoomToLayer(featureLayer);
+ } else {
+ setStyle("progress", "progress hidden");
+ alert("Feature service could not be loaded. Check URL.");
+ }
+ document.getElementById("featureServiceUrl").value = layer.url;
+ }
+ }
+
+ function zoomToLayer(layer) {
+ var params = new esri.tasks.ProjectParameters();
+ params.geometries = [layer.fullExtent];
+ params.outSR = map.spatialReference;
+ geometryService.project(params, function(geometries) {
+ map.setExtent(geometries[0]);
+ });
+ }
+
+ function setMessage(msg) {
+ var element = document.getElementById("userMessage");
+ element.innerHTML = msg;
+ }
+
+ function setStyle(elementName, className) {
+ var element = document.getElementById(elementName);
+ if (element)
+ element.className = className;
+ }
+
+ dojo.addOnLoad(init);
+ </script>
+</head>
+<body>
+ <div class="panel">
+ <div class="titlearea"><span id="titleMessage" class="title-message">Get Feature Service</span></div>
+ <div class="controls">
+ <div class="buttons">
+ ArcGIS REST endpoint URL:
+ <textarea id="featureServiceUrl" rows="3"
+ placeholder="http://services.arcgis.com/oKgs2tbjK6zwTdvi/arcgis/rest/services/Major_World_Cities/FeatureServer/0"
+ value="http://services.arcgis.com/oKgs2tbjK6zwTdvi/arcgis/rest/services/Major_World_Cities/FeatureServer/0"
+ onkeypress="addService_onKeyPress(event);">http://services.arcgis.com/oKgs2tbjK6zwTdvi/arcgis/rest/services/Major_World_Cities/FeatureServer/0
+ </textarea>
+ <button class="btn btn-primary" onclick="addFeatureService();">Add</button>
+ <button class="btn" onclick="removeFeatureService();">Remove</button>
+ </div>
+ </div>
+ <div class="message"><span id="userMessage" class="user-message"></span></div>
+ </div>
+ <div id="mapDiv"></div>
+ <div id="progress" class="progress hidden"></div>
+</body>
+</html>
View
1 index.html
@@ -29,6 +29,7 @@
<li><a href='html/directions/directions.html')><button class="btn btn-extra-wide">Directions</button></a></li>
<li><a href='html/drivetime/drivetime.html')><button class="btn btn-extra-wide">Drive Time</button></a></li>
<li><a href='html/cloud/cloud_sql.html')><button class="btn btn-extra-wide">Cloud SQL</button></a></li>
+ <li><a href='html/cloud/get_feature_service.html')><button class="btn btn-extra-wide">Get Feature Service</button></a></li>
</ul>
</div>
</div>

0 comments on commit 7d347f0

Please sign in to comment.
Something went wrong with that request. Please try again.