[GIS] How to get OpenLayers map object in HTML form

openlayers-2web-mapping

There is a form to within a web page, map of OpenLayers is displayed in the form. I look at the source code of Html, and further a hierarchical state in the form. My goal is to get the Polygon at the bottom, but do not know how to get the map object of OpenLayers.

Html source code

<form id="map_form" method="get" action="#">
  <div id="map_content" class="section map">
   <div id="map_object" class="section object">
    <div id="map" class="olMap">
     <div id="OpenLayers.Map_7_OpenLayers_ViewPort">
      <div id="OpenLayers.Map_7_events">
       <div id="OpenLayers.Map_7_OpenLayers_Container">
        <div id="webtis.Layer.BaseMap_43">
         <div id="OpenLayers.Layer.Vector_67">
          <svg id="OpenLayers.Layer.Vector_67_svgRoot">
           <g id="OpenLayers.Layer.Vector_67_root" style="visibility: visible;" transform="">
            <g id="OpenLayers.Layer.Vector_67_vroot">
             <path id="OpenLayers.Geometry.Polygon_3503" d=" M ...
             ...

Also tried the following methods.

1. map = new OpenLayers.Map (document.getElementById ('OpenLayers.Map_7_OpenLayers_ViewPort'))
2. map = new OpenLayers.Map (document.getElementById ('map_content'))
3. map = new OpenLayers.Map (document.getElementById ('map_object'))

Which method but also map.layers.length was 0.

How can I get the OpenLayers's map object?

Best Answer

You don't have to create a new OL map. The OpenLayers map has already been created inside the form and if everything is ok, the SVG elements will be there. Take in care tha OL can render also on canvas instead of SVG, it depends on how the map is coded.

If you really want to take the drawing coordinates from the generated SVG you can just explore the DOM inside the form (based on its id) to look for a "path" tag.

Related Question