0

I can show WMS PNG format my in map but I can't render GeoJSON and GML formats by the way my URL is correct service. İn addition I used same code in my local server and I can render in my local GeoServer.

Why does Firebug say OpenLayers protocols are undefined. But when I use my local GeoServer and I can edit options and URL and I can show map GML and GeoJSON formats on my local server, but when I add service URL it didn't render, but again I can render WMS image formats. İ didn't use proxy when I work in service URL.

My environment OpenLayers, GeoServer

<!DOCTYPE html>
<html>
<head>
<script src="http://myurl.com/geoserver/openlayers/OpenLayers.js" type="text/javascript"></script>
    <style type="text/css">          
      /* General settings */
        body {
            font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
            font-size: small;
        }
        /* Toolbar styles */
            #toolbar {
            position: relative;
            padding-bottom: 0.5em;
            display: none;
        }
           #toolbar ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }
        #toolbar ul li {
            float: left;
            padding-right: 1em;
            padding-bottom: 0.5em;
        }
        #toolbar ul li a {
            font-weight: bold;
            font-size: smaller;
            vertical-align: middle;
            color: black;
            text-decoration: none;
        }
        #toolbar ul li a:hover {
            text-decoration: underline;
        }
        #toolbar ul li * {
            vertical-align: middle;
        }
        /* The map and the location bar */
        #map {
            clear: both;
            position: relative;
            width: 778px;
            height: 330px;
            border: 1px solid black;
        }
        #wrapper {
            width: 778px;
        }
        #location {
            float: right;
        }
        #options {
            position: absolute;
            left: 13px;
            top: 7px;
            z-index: 3000;
        }
        /* Styles used by the default GetFeatureInfo output, added to make IE happy */
        table.featureInfo, table.featureInfo td, table.featureInfo th {
            border: 1px solid #ddd;
            border-collapse: collapse;
            margin: 0;
            padding: 0;
            font-size: 90%;
            padding: .2em .1em;
        }
        table.featureInfo th {
            padding: .2em .2em;
            text-transform: uppercase;
            font-weight: bold;
            background: #eee;
        }
        table.featureInfo td {
            background: #fff;
        }
        table.featureInfo tr.odd td {
            background: #eee;
        }
        table.featureInfo caption {
            text-align: left;
            font-size: 100%;
            font-weight: bold;
            text-transform: uppercase;
            padding: .2em .2em;
        }
    </style>
</head>
<body onload="init()">
<div id="map"></div>
<script defer="defer" type="text/javascript">  
    OpenLayers.ProxyHost = "/gt/proxy.cgi?url=";
    var lon = 5;
    var lat = 44;
    var zoom = 5;
    var map, layer;

    function init(){
        var bounds = new OpenLayers.Bounds(
                25.663514785385082,35.80899164217125,44.82543228354381,42.10495847294918
            );
            var options = {
                controls: [],
                maxExtent: bounds,
                maxResolution:6541.59135,
                projection: "EPSG:4326",
                units: 'm'
            };
            map = new OpenLayers.Map('map', options);
            map.addControl(new OpenLayers.Control.PanZoomBar({
                position: new OpenLayers.Pixel(2, 15)
            }));
            map.addControl(new OpenLayers.Control.Navigation());
            map.addControl(new OpenLayers.Control.Scale($('scale')));
            map.addControl(new OpenLayers.Control.MousePosition({element: $('location')}));
            //Gml geliyor kardes 
            map.addLayer(new OpenLayers.Layer.Vector("GML", {
            isBaseLayer: true , 
            //styleMap: myStyles,
            protocol: new OpenLayers.Protocol.HTTP({
                url: "http://myurl.com/geoserver/Tarim/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=Tarim:Iller&maxFeatures=50",
                format: new OpenLayers.Format.GML()
            }),
            strategies: [new OpenLayers.Strategy.Fixed()]
        }));
    }
   </script>
</body>
</html>
  • Here is an OpenLayers GeoJSON example: openlayers.org/dev/examples/geojson.html – Martin Dec 24 '12 at 12:21
  • Thx martin for ur answer i know this example . – rusty1119 Dec 24 '12 at 12:25
  • I solve my problem about again proxy . Dont remember guys openlayers use two proxy type one of them "/gt/proxy.cgi?url="; the other one is php proxy . İn my local i use proxy.cgi but when i use service i need php proxy .. But i dont know why :)))) – rusty1119 Dec 25 '12 at 15:37
  • Please use the edit link on your question to add additional information. The Post Answer button should be used only for complete answers to the question. – Simon Dec 26 '12 at 3:11
2

Well OpenLayers.Protocol undefined means that by some reason the OpenLayers library could not be downloaded into client or was not available at time it was used.

Replace your local OpenLayers copy by the site available copy during tests. After you sure all things working replace by your local version.

You have configure a proxy server also. Disable it during tests.

Remove the css part of your comments it is not relevant for solution for now. Also I could not see the tag with a call to the init function.

Did you checked for browser security blocking requests to server? Current browsers implements the CORS policy ( https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS ) for requests.

  • Thx for answer but nothing changed thx for advice i try other browser but nothing changed – rusty1119 Dec 24 '12 at 20:25
  • Could you add the missing html body tag? Also looks like you using a jQuery( $ function ) library. Try a Firefox with Firebug. I guess it is the easiest to use javascript debuger. – cavila Dec 24 '12 at 20:36
  • yes cavila . I use js library no jquery . My html tag also correct – rusty1119 Dec 24 '12 at 20:41

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.