1

I have a mapfile

MAP
  NAME "MapChiTieuDau"
  EXTENT         779275 2222000 788430  2233835  
  SIZE           800 800
  UNITS          dd
  STATUS         ON
  IMAGETYPE      png
  SHAPEPATH      "/ms4w/apps/openlayers-3.8.2/DuLieuBachLongVy/Maps"
  IMAGECOLOR     190 232 255
  FONTSET        "/ms4w/apps/tutorial/fonts/fonts.list"

  WEB
   IMAGEPATH "/ms4w/tmp/"
   IMAGEURL "/ms_tmp/"
   METADATA
      "wms_title" "WMS Demo Server"
      "wms_onlineresource" "/cgi-bin/mapserv.exe?map=/ms4w/Apache/htdocs/Test/wms/BD_ChiTietDau.map"    
      "wms_srs" "EPSG:4326"
      "wms_enable_request" "*"
   END #end METADATA
  END #end web
  PROJECTION
    "init=EPSG:4326"
  END

  SYMBOL
     NAME "circlef"
     TYPE ellipse
     FILLED true
     POINTS
       10 10
     END # POINTS
  END # SYMBOL

  LAYER 
    NAME         "binh_do_15"
    DATA         binh_do_15
    STATUS       ON
    TYPE         LINE
    CLASSITEM    "SOURCE"
    LABELITEM    "SOURCE"
    DEBUG on
    PROJECTION
        "init=EPSG:4326"
    END
    METADATA
        "wms_title" "binh_do_15"
    END
    CLASS
      NAME       "binh_do_15"
      STYLE
        COLOR    174 213 252
      END
      LABEL
        COLOR 183 68 85
        TYPE TRUETYPE
        FONT arial
        SIZE 12
        ANTIALIAS TRUE
        POSITION CL
        PARTIALS FALSE
        MINDISTANCE 300
        BUFFER 4
        STYLE    # since to version 6
          GEOMTRANSFORM 'labelpoly'
          OFFSET 2 2
        END # STYLE      
      END # end of label
    END
  END 

LAYER
  NAME "chitieu_mt"
  TYPE POINT    
  DUMP true 

  PROJECTION
    "init=EPSG:4326"
  END
  METADATA
    "wms_title" "chitieu_mt"
  END
  DEBUG on
  STATUS on
   DATA chitieu_mt


  CLASSITEM    "Dau"
  LABELITEM    "Dau"
  CLASS
    Name "chitieu_mt"
    STYLE
      SYMBOL "circlef"
      SIZE 16
      COLOR 212 3 255
    END
    TEXT (tostring([Dau],"%.2f"))
    END # end of CLASS
  END # end of LAYER
END

and JavaScript code:

<script type="text/javascript">
var map, layer;
var infoControls;
var fromProjection = new OpenLayers.Projection('EPSG:4326'); 
var ll, popupClass, popupContentHTML;

function init(){

    format = 'image/png';
     var bounds = new OpenLayers.Bounds(779275, 2222000,788430, 2233835);

     map = new OpenLayers.Map('map', {
        controls:[
           new OpenLayers.Control.Navigation(),
           new OpenLayers.Control.LayerSwitcher(),
           new OpenLayers.Control.Attribution(),
           new OpenLayers.Control.PanZoomBar(),
           new OpenLayers.Control.LayerSwitcher({'ascending':false}),
           new OpenLayers.Control.ScaleLine(),
           new OpenLayers.Control.MousePosition(),
           new OpenLayers.Control.OverviewMap(),
           new OpenLayers.Control.KeyboardDefaults()
        ],
         numZoomLevels:7,
        maxExtent : bounds
     });
    var bdhw = new OpenLayers.Layer.WMS(
            'MapChiTieuDau','/cgi-bin/mapserv.exe?map=/ms4w/Apache/htdocs/Test/wms/BD_ChiTietDau.map',
            {
                layers: 'chitieu_mt',
                srs: 'EPSG:32628',
                transparent: true,
                format:  format// 'image/gif'
            },  {
                isBaseLayer: true,
                 reproject: true
                 });
    var bdhw2 = new OpenLayers.Layer.WMS(
            'MapChiTieuDau2','/cgi-bin/mapserv.exe?map=/ms4w/Apache/htdocs/Test/wms/BD_ChiTietDau.map',
            {
                layers: 'binh_do_15',
                srs: 'EPSG:32628',
                transparent: true,
                format:  format//'image/gif'
            },  {
                isBaseLayer: false,
                 reproject: true
                 });
        map.addLayers([bdhw,bdhw2]);
        map.zoomToExtent(bounds);

        var vectorLayer = new OpenLayers.Layer.Vector("Overlay");

        var product= <?php echo json_encode($data); ?>;
             for( var i=0;i<product.length;i++ ) {
                var aboutMarker="<table border='3'><tr><td rowspan='4'><img src='img/hb2-7494d.gif' height='100px' alt='Sakura'/></td></tr><tr><td> Longitude: "+product[i][0]+"</td></tr><tr><td> Latitude: "+product[i][1]+"</td></tr><tr><td> Thông tin dầu: "+product[i][2]+"</td></tr></table>";

                var feature = new OpenLayers.Feature.Vector(
                    new OpenLayers.Geometry.Point(product[i][0],product[i][1]).transform(fromProjection,map.getProjectionObject()),
                        {description:aboutMarker} ,
                        {externalGraphic:'img/marker.png',graphicHeight:25,graphicWidth:21,graphicXOffset:-12,graphicYOffset:-25}
                    );
                vectorLayer.addFeatures(feature);
             }
             map.addLayer(vectorLayer);
            var controls = {
              selector: new OpenLayers.Control.SelectFeature(vectorLayer, { onSelect: createPopup, onUnselect: destroyPopup })
            };

            map.addControl(controls['selector']);
            controls['selector'].activate();

   function createPopup(feature) {
  feature.popup = new OpenLayers.Popup.FramedCloud("pop",
      feature.geometry.getBounds().getCenterLonLat(),
      null,
      '<div class="markerContent">'+feature.attributes.description+'</div>',
      null,
      true,
      function() { controls['selector'].unselectAll(); }
  );
  //feature.popup.closeOnMove = true;
  map.addPopup(feature.popup);
}

function destroyPopup(feature) {
  feature.popup.destroy();
  feature.popup = null;
}
}

</script>

I want to show all overlays and base Llayers like a example in dev.Openlayers.org, this is: http://dev.openlayers.org/examples/getfeatureinfo-popup.html

All layers overlapping. it only shows one that bdhw or bdhw2. How do I have to fix?

1

I have used "singleTile: true". It like:

 var bdhw = new OpenLayers.Layer.WMS(
            'MapChiTieuDau','/cgi-bin/mapserv.exe?map=/ms4w/Apache/htdocs/Test/wms/BD_ChiTietDau.map',
            {
                layers: 'chitieu_mt',
                srs: 'EPSG:4326',
                transparent: true,
                format:  format// 'image/gif'
            },  {
                isBaseLayer: false,
                 singleTile: true
                 });

My problem has fixed success!

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.