Spatial Reference changes after adding OpenStreetMap layer from 4326 to 102100

3267
3
06-11-2016 09:47 AM
ArminPourbeik
New Contributor II

Hi,

I'm using a featureLayer, I want to use OSM as a base map, after adding osm layer my map spatial reference changes from 4326 to 102100 (web Mercator), even if I set my osm layer spatial reference to 4326, how can I fix this problem?

thanks;

function startup() {

    var sr = new esri.SpatialReference({wkid: 4326});

    var startextent = new esri.geometry.Extent(

        50.9484,

        35.9424,

        52.0264,

        36.4271,

        sr

    );

    lyr_branches = new esri.layers.FeatureLayer('http://localhost:6080/arcgis/rest/services/DayBank/MapServer/7', {

        mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,

        id: "branches",

        outFields: ['*']

    });

    map = new esri.Map('map', {

        extent: startextent,

        center: [51.420598, 35.721900],

        zoom: 11,

        fadeOnZoom: true,

        minZoom: 10,

        spatialReference: new esri.SpatialReference({wkid: 4326})

    });

     

    osm = new esri.layers.OpenStreetMapLayer({

        id: "osm",

        initialٍExtent: startextent,

        spatialReference: new esri.SpatialReference({

            wkid: 4326

        }),

        center: [51.420598, 35.721900]

    });

 

    var selectionSymbol = new esri.symbol.SimpleMarkerSymbol();

    selectionSymbol.setSize(20);

    selectionSymbol.setColor(new dojo.Color([255, 0, 0, 0.5]));

    lyr_branches.setSelectionSymbol(selectionSymbol);

 

//    map.addLayer(osm);

    map.addLayer(lyr_branches);

 

    var featureTable = new esri.dijit.FeatureTable({

        featureLayer: lyr_branches,

        map: map,

        editable: false,

        showGridHeader: false,

        showGridMenu: false,

        showDataTypes: false,

        outFields: ["PostalCode", "Telephone", "Fax", "Address", "Code", "Name"]

    }, 'myTableNode');

    featureTable.startup();

    //create query task

    queryTask = new esri.tasks.QueryTask('http://localhost:6080/arcgis/rest/services/DayBank/MapServer/7');

    cf = new esri.tasks.ClosestFacilityTask('http://localhost:6080/arcgis/rest/services/DayBank/NAServer/Closest%20Facility');

0 Kudos
3 Replies
RobertScheitlin__GISP
MVP Emeritus

Armin,

  Almost all esri basemaps are web mercator 102100. So it is normal for the maps spatial reference to change to 102100 after applying an esri basemap.

ArminPourbeik
New Contributor II

thanks for your answer Robert,

I'm getting user's current location with HTML5 Geolocation API which gives me coordinates in 4326 Spatial Reference. as I want to use this point as  incidents in closest facility network analysis, I must convert this point's spatial reference to my map and facilitiy points which is 102100, so how can I do that? I tried proj4js but I didn't succeed...

0 Kudos
ArminPourbeik
New Contributor II

Oh, I just found esri.geometry.lngLatToXY() method.

thanks any way;)