Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i've got something error when I run my code in firebug..

here this code :

<script type="text/javascript" src="OpenLayers.js"></script>

            mysql_connect("localhost", "root", "") or die("koneksi gagal");
            mysql_select_db("jogja") or die ("database tidak bisa dibuka");

                $query="SELECT * FROM jogja ORDER BY idkab";
                $result= mysql_query($query);


                    $value[$data["idkab"]] = $data["value"];
                    $kab[$data["idkab"]] = $data["kab"];

                $bataskelas = array(0, 500, 1000, 2000);
                $warnakelas = array("#EEFFFF", "#6DD5FF", "#19A3FF", "#0048FF");

        <script type="text/javascript">

            var map;
            var jogja;
            var data = <?php echo json_encode($value); ?>;
            var kab = <?php echo json_encode($kab); ?>;
            var batas = <?php echo json_encode($bataskelas); ?>;
            var warna = <?php echo json_encode($warnakelas); ?>;    

        function init(){
            map = new OpenLayers.Map('map',{
            controls: [
                new OpenLayers.Control.Navigation(),
                new OpenLayers.Control.PanZoom(),
                new OpenLayers.Control.ScaleLine(),
                new OpenLayers.Control.MousePosition(),

            var context = {
                getColor: function(feature){
                var id = feature.attributes.IDKAB;
                var val=data[id];
                var color = "white";

                var i =0;
                while(i < batas.length-1){
                    if (val < batas[i+1]){
                        color = warna[i];
                    if (val !=null && color == "white"){
                        color = warna[batas.length-1];
                    return color;

                getLabel: function (feature){
                    return wilayah[feature.attributes.IDKAB];

            var template = {
                strokeColor: "#808080",
                strokeWidth: 1,
                graphicZIndex: 1,
                fillColor: "${getColor}",
                label: "${getLabel}",
                labelAlign: "cm"


            var style = new OpenLayers.Style(template, {context: context});
            var myStyle = new OpenLayers.StyleMap(style);

            jogja = new OpenLayers.Layer.GML ("GML", "gml/jogja.gml", {
                        isBaseLayer: true, styleMap: myStyle});

  {'loadend': onLoadEnd});


        function onLoadEnd(){
            var ext = jogja.getDataExtent();


and here screenshot error : enter image description here

what should I do to avoiding this error?? because of this error the map don't show out..

-thanks for answering-

share|improve this question
For debugging purpose use not compressed OL version: lib/OpenLayers.js instead OpenLayers.js in your case. And if any errors occured firebug will show in what part of OpenLayers code it happened. – drnextgis Jun 29 '12 at 22:00

I haven't run your code, but I would guess the error happens at map.zoomToMaxExtent(); at this point you haven't told your map what its maximum extent is. Before the GML loads (which then triggers onLoadEnd) the map has no data, so its bounds are null.

Try removing map.zoomToMaxExtent(); from your init function. The map should do what you expect when the GML has loaded.

If this doesn't help then you need to either follow drnextgis's advice and use a more readable OL script for debugging or litter your code with console.log or (gasp) alerts so you can see how far your code gets before failing.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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