3

I get an error "Map: Geometry (wkid: 3301) cannot be converted to spatial reference of the map (wkid: 4326)" when I want to add only graphics layer. I found that spatial reference for a map is defined either by the extent passed to the map constructor or by the first layer added to the map, so I think that problem is that my layer is defined without property about wkid. My question is how to properly define it. My code is following (it works when I add wms layer first, but I want to add only the "vectorLayer"):

 var map;
    require([
        'esri/map', 'esri/layers/WMSLayer', 'esri/layers/WMSLayerInfo', 'esri/geometry/Extent',
        'dojo/_base/array', 'dojo/dom', 'dojo/dom-construct', 'dojo/parser',
        'dijit/layout/BorderContainer', 'dijit/layout/ContentPane', "dojo/_base/json" , "esri/request", 'dojo/domReady!'
    ], function (Map, WMSLayer, WMSLayerInfo, Extent, array, dom, domConst, parser, dojoJson, esriRequest, request, xhr) {
        parser.parse();
        var spatialReference2 = new esri.SpatialReference({"wkt": 'PROJCS["Estonian Coordinate System of 1997",GEOGCS["EST97",DATUM["D_Estonia_1997",SPHEROID["GRS_1980",6378137,298.257222101]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]],PROJECTION["Lambert_Conformal_Conic"],PARAMETER["standard_parallel_1",59.33333333333334],PARAMETER["standard_parallel_2",58],PARAMETER["latitude_of_origin",57.51755393055556],PARAMETER["central_meridian",24],PARAMETER["false_easting",500000],PARAMETER["false_northing",6375000],UNIT["Meter",1]]'
        });
        var map = new esri.Map("map",
                {
                    spatialReference: spatialReference2,
                    center: new esri.geometry.Point(550000, 6520000, new esri.SpatialReference({ wkid: 3301 })),
                    extent: new esri.geometry.Extent(350000, 6370000, 750000, 6630000, new esri.SpatialReference({"wkid": 3301})),
                    zoom: 4
                });
//        var wmsLayer = new WMSLayer('http://kaart.maaamet.ee/wms/alus?', {
//            resourceInfo: {
//                extent: new Extent(350000, 6370000, 750000, 6630000, {
//                    wkid: 3301
//                }),
//                layerInfos: new WMSLayerInfo({
//                    name: 'MA-ALUS',
//                    title: 'Maaameti WMS MA-ALUS'
//                })
//            },
//            visibleLayers: ['MA-ALUS']
//        });
//        map.addLayers([wmsLayer]);

        var vectorLayer = new esri.layers.GraphicsLayer();
        var layerUrl = 'http://loom-gis.geo.ut.ee:8080/geoserver/ermas/ows?service=WFS&' +
                'version=1.1.0&request=GetFeature&typeName=ermas:testdata_geopnt&' +
                'outputFormat=text/javascript&format_options=callback:loadFeatures&maxFeatures=300&' +
                'srsname=EPSG:3301&EPSG:3301';
        var loadFeatures = function (response) {
            for (var i = 0; i < response.features.length; i++) {
                var geometry = new esri.geometry.Point(response.features[i].geometry.coordinates[0], response.features[i].geometry.coordinates[1], new esri.SpatialReference({ wkid: 3301 }));
                var symbol = new esri.symbol.SimpleMarkerSymbol();
                var graphic = new esri.Graphic(geometry, symbol);
                vectorLayer.add(graphic)
            }
            map.addLayers([vectorLayer]);
        };
        window.loadFeatures = loadFeatures
        esri.request({
            url: layerUrl,
            content: { f: "json" },
            handleAs: "json",
            callbackParamName: "loadFeatures"
        });
    });
  • It is hard to look at the code on my mobile device, but one thing I notice, although most likely not related, is that you are mixing AMD and legacy code. – BritishSteel Feb 4 '15 at 20:29
  • There is a sample called any projection which shows how to feature layer without a basemap. Does that help? – Stephen Lead Feb 4 '15 at 22:33
  • @StephenLead " To use a projection other than a service's default, define esri.Map's spatial reference by specifying the extent constructor option." but I have map extent defined in 3301, but it says that my map is in 4326... – Anuket Feb 5 '15 at 7:45
  • @StephenLead now I see that my extent does not change, it is default extent of 4236. How to define it properly? – Anuket Feb 5 '15 at 8:35
2

The solution is to add a dummy layer. We can create a "fake" feature layer from JSON to trick the map into the desired projection. This feature layer should have the target spatial reference.

 var layerDefinition = {
        "extent": {
            "xmin": 0,
            "ymin": 0,
            "xmax": 0,
            "ymax": 0,
            "spatialReference": {
                "wkid": 3301,
                "latestWkid": 3301
            }
        },
        "fields": [{
            "name": "OBJECTID",
            "type": "esriFieldTypeOID",
            "alias": "OBJECTID",
            "domain": null
        }]
    }

    var featureCollection = {
        layerDefinition: layerDefinition,
        featureSet: null
    };

    var featureLayer = new esri.layers.FeatureLayer(featureCollection, {
        mode: esri.layers.FeatureLayer.MODE_SNAPSHOT
    });

    window.app.map.addLayers([featureLayer, vectorLayer]);
  • It is not an option for me. I think to resolve a problem I need just define extent properly, but I have problems with it. – Anuket Feb 5 '15 at 8:36
  • Is it an option to add a fake layer? We could add a fake tile layer pretending to be 3301. If yes, i can explore this option. – Aamir Suleman Feb 5 '15 at 12:02
  • Unfortunately no – Anuket Feb 5 '15 at 12:27
  • 1
    This looks like its possible with featureLayers developers.arcgis.com/javascript/jssamples/… – Aamir Suleman Feb 5 '15 at 22:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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