4

I'm new in OpenLayers. I'd like to use mapservice of ArcGIS server 10 in open layers.I search and found examples of using an ArcGIS Server 9.3 Rest API layer for OpenLayers. I found OpenLayers.Layer.ArcGIS93Rest instance but not ArcGIS 10 . How can I use ArcGIS server 10 services in Openlayers? I wrote the below code . I use ArcGIS server 10 and The REST is working right .

<!DOCTYPE html>

<html lang='en'>
<head>

    <title>My OpenLayers Map</title>
       <script type='text/javascript' src='OpenLayers.js'></script>
    <script type='text/javascript'>

        var map;

        function init() {

          map = new OpenLayers.Map('map_element',{});
var arcgis = new OpenLayers.Layer.ArcGIS93Rest("MyName","http://xxxxxxx/ArcGIS/rest/services/test/MapServer",

          {layers: "show:0,1,2,3,4"});

                    map.addLayers([arcgis]);

                    }

    </script>
</head>

<body onload='init();'>
<div id='map_element' style='width:1000px; height:500px;'>
</div>
</body>
</html>
5
  • 1
    Why don't you try using the ArcGIS9.3 Layer? It should work for ArcGIS Server 10.x as well. Aug 10, 2013 at 12:23
  • @DevdattaTengshe I use this code but it's not working. var map; function init() { map = new OpenLayers.Map('map_element',{}); var arcgis = new OpenLayers.Layer.ArcGIS93Rest("MyName", "http://.../ArcGIS/rest/services/silver_test/MapServer", {layers: "0,1,2,3"} ); map.addLayers([arcgis]); }
    – BBG_GIS
    Aug 10, 2013 at 15:44
  • 1
    Can you reference the service via WMS, new OpenLayers.Layer.WMS()?
    – artwork21
    Aug 10, 2013 at 17:06
  • @artwork21 yes . it works for arcgis service . thanks
    – BBG_GIS
    Aug 10, 2013 at 17:30
  • i have encounterd the same problems using OpenLayers to add ArcGis Rest Mapserver,i tried three ways,but they don't render correctly,such as,when i dragging the map the vector didn't move with the baseMap,so,how did you solved this problem at last, any advices would be great,thank you !
    – ethel hao
    Oct 11, 2013 at 5:38

3 Answers 3

5

Without Looking at your code, I can't say why you can't access your ArcGIS Server 10 layer. But I can access ArcGIS map service layers in my OpenLayers App in the following ways:

  • When the map service is a tiled Mapservice in WebMercator, I can use the following code:

layer = new OpenLayers.Layer.XYZ( "ESRI", "http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer/tile/${z}/${y}/${x}", {sphericalMercator: true} );

  • When I have a dynamic mapservice, I can use the following code:

layer = new OpenLayers.Layer.ArcGIS93Rest( "ArcGIS Server Layer", "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/export", {layers: "show:0,2"});

There are two working examples on the OpenLayers website:

  1. Basic ESRI Map Cache Example
  2. ArcGIS Server 9.3 Rest API Example
2
  • I Wrote the code in the question. It's not working. is there an error in my code ?
    – BBG_GIS
    Aug 11, 2013 at 21:22
  • @wetland Your code seems to be missing the /export in the url parameter of the Layer constructor. Aug 12, 2013 at 2:49
3

If you have switched on the WMS capability of the map service, then you can consume the service as a WMS Layer, using the OpenLayers.Layer.WMS() class.

0

Now is year 2018, openlayers is version 5.x.x

for arcgis rest api map server url like below,

 var url = 'https://sampleserver1.arcgisonline.com/ArcGIS/rest/services/' +
      'Specialty/ESRI_StateCityHighway_USA/MapServer';

ArcGIS REST MapService as tiles. This source type supports Map and Image Services.

example:

ArcGIS REST MapService as tiles

For feature server url like below:

var serviceUrl = 'https://sampleserver3.arcgisonline.com/ArcGIS/rest/services/' +
      'Petroleum/KSFields/FeatureServer/';

example:

ArcGIS REST Feature Service

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.