[mapserver-users] asking help

Boubacar Bah bahbouba.909 at gmail.com
Sat Oct 16 04:12:55 PDT 2021


hello everyone ; recently l tried to use openlayers to create my own map
with mapserver. my program work well if try just to display a open layer
map in a browser *but if l try to add the interaction tools like modify,
snap , draw* the program don't work. this is my source code bellow if
someone can hem me with the interaction library of openlayer.
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="
https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.8.1/css/ol.css
" type="text/css">
    <style>
      .map {
        height: 400px;
        width: 100%;
      }
    </style>
    <script src="
https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.8.1/build/ol.js
"></script>
    <script src="https://unpkg.com/elm-pep"></script>
    <title>OpenLayers example</title>
  </head>
  <body>
    <h2>My bah</h2>
    <div id="map" class="map"></div>
    <div id="mouse-position"></div>
    <div id="raster-button">
      <button onclick= "raster_switch()">Raster</button>
    </div>
    <div id="dessin-button">
      <button onclick="add_creer()">Dessiner</button>
    </div>
    <div id="stop-button">
      <button onclick="stop()">Stop</button>
    </div>
    <div id="modify-button">
      <button onclick="add_modify()">Modifier</button>
    </div>
    <script type="text/javascript">
      var raster = new ol.layer.Tile({
           source: new ol.source.OSM()
      });
      var vector = new ol.layer.Vector({
        source: new ol.source.Vector({
        url: '
https://raw.githubusercontent.com/openlayers/openlayers/main/examples/data/geojson/countries.geojson
',
        format: new ol.format.GeoJSON(),
         })
      });
      var map = new ol.Map({
        controls: ol.control.defaults().extend([
          new ol.control.MousePosition({
            coordinateFormat: ol.coordinate.createStringXY(4),
            projection: 'EPSG:4326',
            className: 'custom-mouse-position',
            target: document.getElementById('mouse-position'),
            undefinedHTML: ' '
          }),
          new ol.control.ScaleLine()
        ]),
        target: 'map',
        layers: [raster, vector],
        view: new ol.View({
          center: [0, 0],
          zoom: 2
        })

      });
      function raster_switch(){
        if (raster.getVisible()){   //si le raster est visible
        raster.setVisible(false)    //Nous l'éteignons
        }
        else{
          raster.setVisible(true)   //Sinon nous l'affichons
        }
      }
this is my code witch work but if l try to add this code below
let draw; // global so we can remove it later
      function add_creer(){
          draw= new.ol.interaction.Draw({
            source: vector.getSource(),
            type: "Polygon",
          });
          map.addInteraction(draw);
          //appeler snap apres draw
          add_snap()
      }
the browser send a blank page if some one can help me to correct this code
thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapserver-users/attachments/20211016/fcbb4393/attachment.htm>


More information about the MapServer-users mailing list