2017-05-20 7 views
-1

이 문제를 해결하려고했지만 며칠 동안 올바른 대답을 얻지 못했습니다. 여기서 문제는 나도 몰라''Uncaught SyntaxError : JSON에서 예상치 못한 토큰 < "openlayers를 사용하여 위치" '에 js

<HTML> 
<head> 
    <link rel="stylesheet" href="https://openlayers.org/en/v4.1.1/css/ol.css" type="text/css"> 
    <!-- The line below is only needed for old environments like Internet Explorer and Android 4.x --> 
    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script> 
    <script src="https://openlayers.org/en/v4.1.1/build/ol.js"></script> 
</head> 
<center> 
<div id="mapid" style="width: 600px; height: 500px;"></div> 
</center> 
<script> 
var vectorSource = new ol.source.Vector({ 
     format: new ol.format.GeoJSON(), 
     url: function(extent) { 
      return 'http://localhost:8080/geoserver/opengeo/ows?service=WFS&' + 
      'version=1.0.0&request=GetFeature&typeName=opengeo:comgeo&' + 
      'maxFeatures=50'+ 
      'outputFormat=application%2Fjson' ; 

     }, 
     strategy: ol.loadingstrategy.bbox 
     }); 



     var map = new ol.Map({ 
     layers: [ 
     new ol.layer.Vector({ 
     source: vectorSource, 
     style: new ol.style.Style({ 
      stroke: new ol.style.Stroke({ 
      color: 'rgba(0, 0, 255, 1.0)', 
      width: 2 
      }) 
     }) 
     }) 
     ], 
     target: document.getElementById('mapid'), 
     view: new ol.View({ 
      center: [-9, 30], 
      maxZoom: 19, 
      zoom: 5 
     }) 
     }); 

</script> 

</HTML> 

: 나는 WFS가 openlayers 도구 geoserver에서 요청과지도를 삽입하려고하지만 난이 오류를 얻을 :

Uncaught SyntaxError: Unexpected token < in JSON at position 0 
    at JSON.parse (<anonymous>) 
    at Jl (ol.js:342) 
    at wm.k.Pa (ol.js:342) 
    at T.<anonymous> (ol.js:340) 

을이 내 코드입니다 json 문제 및 openlayers가있는 anythig를 찾지 못했기 때문에 ... 감사합니다.

+0

이 URL에 도달하면 애플리케이션이받는 응답을 업로드 할 수 있습니까? http : // localhost : 8080/geoserver/opengeo/ows? service = WFS & version = 1.0.0 & request = GetFeature & typeName = opengeo : comgeo & axFeatures = 50outputFormat = application/json –

+0

@OliverBarnwell 내지도 파일의 geojson farmat을 제공합니다. –

+0

{ "type": "FeatureCollection"..... –

답변

1

WFS 요청이 유효하지 않습니다.

'maxFeatures=50' 

당신은 또한 WFS 요청의 BBOX을 설정하지 않는

'maxFeatures=50&' 

에 변경합니다. 따라서 bbox 전략을 제거하거나 WFS URL에

&BBOX=' + extent.toString() 

을 추가해야합니다.

+0

나는 그 모든 것을 변경했지만 동일한 오류가 발생했습니다. –

+0

개발자 콘솔에서 GeoServer의 응답을보고 XML의 오류 메시지를 확인하십시오. – ahocevar