Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
469 views
in Technique[技术] by (71.8m points)

ajax - Remote GeoJson layer not appearing in OpenLayers map

I have a geojson url endpoint that shows correctly in QGIS, ArcMap and using the ArcGIS Javascript API when loading, but won't when using through OpenLayers.

Currently this is the portion of my script where I am trying to load the data:

                new ol.layer.Vector({
                  // A layer must have a title to appear in the layerswitcher
                  title: 'Property Parcels',
                  // Again set this layer as a base layer
                  type: 'data',
                  visible: true,
                  style: styleFunction,
                  source:  new ol.source.Vector({
                      projection : 'EPSG:3857',
                      url: '{{url('parcels/geojson')}}',
                      format: new ol.format.GeoJSON()
                  }),
                }),

Other layers load fine, but I am trying to get away from the formatting of GeoJson objects on the page and more to url endpoints.

You can find the sample geojson data here:

{

    "type":"FeatureCollection",
    "features":[
        {
            "type":"Feature",
            "properties":{
                "type":"parcel",
                "ParcelID":"070711431009"
            },
            "geometry":{
                "type":"MultiPolygon",
                "coordinates":[
                    [
                        [
                            [
                                -104.739810985448,
                                40.5869690039517
                            ],
                            [
                                -104.740242592446,
                                40.5869539996775
                            ],
                            [
                                -104.740253583381,
                                40.5871377169226
                            ],
                            [
                                -104.739821976404,
                                40.5871527203439
                            ],
                            [
                                -104.739810985448,
                                40.5869690039517
                            ]
                        ]
                    ]
                ]
            }
        },

And I should mention that the ajax does retrieve the response from the url, so I know it is firing, it's just not adding any features to the map.

question from:https://stackoverflow.com/questions/65878834/remote-geojson-layer-not-appearing-in-openlayers-map

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...