您好,示例代码是这样的:
<script type="text/javascript"> var host = document.location.toString().match(/file:\/\//) ? "http://192.168.1.8:8090" : 'http://' + document.location.host; var local, map, layer, vectorLayer, markerLayer, drawPoint, select, nodeArray = [], pathTime, pathListIndex = 0, routeCompsIndex = 0, style = { strokeColor: "#304DBE", strokeWidth: 3, pointerEvents: "visiblePainted", fill: false }, styleGuidePoint = { pointRadius: 10, externalGraphic: "./images/walk.png" }, styleGuideLine = { strokeColor: "#25FF25", strokeWidth: 6, fill: false }, url1 = host + "/iserver/services/map-changchun/rest/maps/长春市区图", url2 = host + "/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun"; function init() { vectorLayer = new SuperMap.Layer.Vector("Vector Layer"); drawPoint = new SuperMap.Control.DrawFeature(vectorLayer, SuperMap.Handler.Point); select = new SuperMap.Control.SelectFeature(vectorLayer, { onSelect: onFeatureSelect, onUnselect: onFeatureUnselect }); drawPoint.events.on({ "featureadded": drawCompleted }); map = new SuperMap.Map("map", { controls: [ new SuperMap.Control.LayerSwitcher(), new SuperMap.Control.Zoom(), new SuperMap.Control.Navigation({ dragPanOptions: { enableKinetic: true } }), drawPoint, select], units: "m" }); layer = new SuperMap.Layer.TiledDynamicRESTLayer("Changchun", url1, { transparent: true, cacheEnabled: true }, { maxResolution: "auto" }); layer.events.on({ "layerInitialized": addLayer }); markerLayer = new SuperMap.Layer.Markers("Markers"); }
function addLayer() { map.addLayers([layer, vectorLayer, markerLayer]); map.setCenter(new SuperMap.LonLat(4503.6240321526, -3861.911472192499), 1); } function selectPoints() { clearElements(); drawPoint.activate(); } function drawCompleted(drawGeometryArgs) { var point = drawGeometryArgs.feature.geometry, size = new SuperMap.Size(44, 33), offset = new SuperMap.Pixel(-(size.w / 2), -size.h), icon = new SuperMap.Icon("../theme/images/marker.png", size, offset); markerLayer.addMarker(new SuperMap.Marker(new SuperMap.LonLat(point.x, point.y), icon)); nodeArray.push(point); }
</script>
红色的路径是我改成本地服务器的地址,但是调试的时候,js会报:iserver/services/map-changchun/rest/maps/%E9%95%BF%E6%98%A5%E5%B8%82%E5%8C%BA%E5%9B%BE.json Failed to load resource: the server responded with a status of 404 (Not Found)
这个路径的地址应该是:http://192.168.1.8:8090/iserver/services/map-changchun/rest/maps/%E9%95%BF%E6%98%A5%E5%B8%82%E5%8C%BA%E5%9B%BE.json
可是由于不知道这个josn如果生成的,导致我不知道如何修改这个路径。
你把var host = document.location.toString().match(/file:\/\//) ? "http://192.168.1.8:8090" : 'http://' + document.location.host;这段删掉,url改成
url1="http://192.168.1.8:8090/iserver/services/map-changchun/rest/maps/长春市区图", url2="http://192.168.1.8:8090/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";试一下