0

Here actually am trying to achieve multipolygon on wms layer in openlayers 3. In this i'm calling a php file which is giving the output of geojson format but i don't have any idea where i'm doing . I have checked my json list which works fine. I'm not getting What is the thing i'm missing in javascript please help me on that. I have also tried the bbox strategy but that doesn't work too.

Check the plunker of it https://plnkr.co/edit/YEG6vCA8yvi3KNzVt2W6?p=preview

This the format i have in my database in geom field.

0106000020E610000001000000010300000001000000320000000058534524EA63C00000FC3B54743B400010D4D8009962C00000F4CAC7BF34400070673120FC60C0000094AF76DA2E4000D0AFB680BE5EC00000344E5E3524400010E0CE7F835BC00000285939071A40000088C77E4D58C00000B0AB62ED0FC000C0C6D40E4C56C00000682E84F725C000E0C8F9708555C000001827AB1837C0000040EB935D56C0000016C4629141C00080DD01150058C0000046B0721E44C000A0F50317A059C00000C8B2DDF144C000008FA2A9D95AC000004F3978A446C000E0307DFC165CC00000F2C986ED4AC000E099686F225EC0000009430F554EC000A002FDB0C35FC00000B25FA60250C000E03D1B7AB260C000806F13C5DA50C000406987CBEA61C0000094F389B051C000A0B0DEA4EE62C000809E84121952C0005015FE2C8A63C0000085C08B1552C000A8EA9EDDF163C000801DE1311352C000A8AEBE658D64C00000051CAB0F52C00080390F3EC164C000000C2C7E0E52C0005012A2865B65C0000080E9242E51C000C0F61A062966C0000048186BBC4FC000A062E341D66540000054FB5F3D4CC000D8DC49E9D4644000008540279B49C000401532B99F6340000009B194F646C000400189F8D0624000003CB55A1046C00000D22800CF614000005A68F44A44C000D8E21EE00061400000EFB6E48742C00060E7ADBE31604000000A40323B41C000A0900453C65E400000C6F4C51940C000A0BB0B456C5D4000002647CD0E3CC000105EB192005B4000002CECDCBF36C000A02124D015594000003800DEB32CC000C0E53A03615840000000A024BD0EC000A0F481166F58400000A07666280B4000F0D714EA3C594000009CE7C8BE2A400010D42370E45A4000003A8C1060394000E0576E31235E400000C80817F43A4000688D6ED11460400000BA6E8DDC3A4000B8D8C19AB16040000080A0BB413E400058AD54648C614000001BEF6CBD414000E059F64162624000005938C7A543400088E303637963400000463607F743400058FA01808E644000005BAEBB58434000B81451724A6540000020FA8EAE42400040CD56F15F664000002F0DBC97424000704585323265C0000009922A8540400058534524EA63C00000FC3B54743B40

i just want it to convert in latlong form

Here is my javascript code of layers

<!DOCTYPE html>
<html>
<head>
<title>Single image WMS example</title>
<link rel="stylesheet" href="http://openlayers.org/en/v3.14.2/css/ol.css" type="text/css">
<script src="jquery-2.0.3.js" type="text/javascript"> </script>
    <script src="http://openlayers.org/en/v3.14.2/build/ol.js"></script>

</head>
<body>    

    <div id="map" class="map"></div>

<script>    

var lulayer = 

  new ol.layer.Image({       

     source: new ol.source.ImageWMS({

          url: 'http://localhost:8080/geoserver/vhy/wms',
          params: {
                LAYERS: 'layername'
          }                      

        })
        });

var vector = new ol.layer.Vector({
  source: new ol.source.Vector({
    url: 'layernamegeojson.php',
    format: new ol.format.GeoJSON()
  })
});

    var map = new ol.Map({
  layers: [landuselayer , vector],

            view: new ol.View({
                center: ol.proj.fromLonLat([79.17436, 21.01668]),
                zoom: 13
                                }),

            target: 'map'
        });  


        </script>
</body>
</html>

Basically I wanted to achieve this output in form of mutipolygon on WMS images by calling this geojson.php page output format into javascript.

11
  • Try to setup a minimal jsfiddle to show us your problem. And have a look to official Geojson example, that could help you.
    – oterral
    Mar 7, 2016 at 7:43
  • @oterral how can i upload shapefile into jsfiddle .i can explain you if u have any doubt like i have map of landuse /landcover now on that one i wanted to show area of waterbodies ,builtup etc, and that will be highlighted through polygon so the result i'm getting through php in from of geojson geometry. That php page result how can i show into my map.
    – ads
    Mar 7, 2016 at 12:04
  • @oterral hi i have created plunker of it check it plnkr.co/edit/YEG6vCA8yvi3KNzVt2W6?p=preview . in this one i'm trying to fetch the file of geojson but the output doesn't come. Please check where i'm doing wrong if u have any idea. Here i have copy paste the output of my php file in multipolygon.geojson
    – ads
    Mar 15, 2016 at 5:57
  • You need to defined the correct CRS of your data in your GeoJSON file. And use a more recent version of Openlayers can't be bad.
    – oterral
    Mar 16, 2016 at 17:29
  • @oterral i'm using 3.5.0 version of openlayers and i have check the crs of data in QGIS which was correct CRS WGS 84 EPSG:4326
    – ads
    Mar 17, 2016 at 6:12

1 Answer 1

1

If the question is "How can I display the result of my php file?", here is the piece of code:

var vector = new ol.layer.Vector({
  source: new ol.source.Vector({
    url: '[path to your php file]/geojson.php',
    format: new ol.format.GeoJSON()
  })
});
map.addLayer(vector);

that comes from the official example

UPDATE:

This is the solution if your GeoJSON is correctly formatted with the crs defined inside it or if the GeoJSON is in EPSG:4326, otherwise if no crs defined in the GeoJSON (like you) you need to define the data projection in the ol.format.GeoJSON constructor :

var vector = new ol.layer.Vector({
  source: new ol.source.Vector({
    url: '[path to your php file]/geojson.php',
    format: new ol.format.GeoJSON({
        defaultDataProjection: 'EPSG:32644'
    })
  })
});
map.addLayer(vector);

Don't forget to include the proj4js library and the projection you use to your html page:

<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.14/proj4.js" ></script>
<script src="//epsg.io/32644.js"></script>
11
  • Here is a working jsfiddle with the geojson you give inline jsfiddle.net/00j1q339/2 so if your PHP file returns a correct geojson the code upper should works as expected.
    – oterral
    Mar 8, 2016 at 10:15
  • updated my code . N done like you said but it doesn't show any error and any polygon on it. And i'm also receiving the php result like you did in your geojson form . Where i'm doing wrong can you please check it.
    – ads
    Mar 8, 2016 at 12:24
  • And when i paste my php page result on your fiddle then it works. is there anything i'm missing in my code
    – ads
    Mar 8, 2016 at 13:13
  • Do you have a url where I can access to this php file?
    – oterral
    Mar 9, 2016 at 8:40
  • no its not on the server but i can you show the result of php file.
    – ads
    Mar 9, 2016 at 9:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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