WordPress.org

Ready to get started?Download WordPress

Forums

OSM - OpenStreetMap
[resolved] suggestions: add hooks and/or circles/discs display (2 posts)

  1. alm06130
    Member
    Posted 1 year ago #

    I had a request to add circular zones to maps.
    To fullfill this request, I had to modify osm.php and osm-openlayers.php, to add parameters and subroutines. I think it would be nice to have hooks which permit to add fonctionnalities.

    modifications I have done
    in osm.php
    attributes of shortcodes

    ,
      /// discs
        /// discs parameters
        'disc_center_list'         => '',          // in decimal degrees
        'disc_radius_list'         => '',          // in meters
        'disc_center_opacity_list' => '0.5',       // float 0->1
        'disc_center_color_list'   => 'red',       // html name or #rvb or #rrvvbb
        'disc_border_width_list'   => '3',         // integer
        'disc_border_color_list'   => 'blue',      // html name or #rvb or #rrvvbb
        'disc_border_opacity_list'  => '0.5',      // float 0->1
        'disc_fill_color_list'      => 'lightblue',// html name or #rvb or #rrvvbb
        'disc_fill_opacity_list'    => '0.5'       // float 0->1
      /// end discs

    modifying $output for discs:

    /// add the disc(s)
    
        /// discs parameters
        ///'disc_center_list'         => '',
        ///'disc_radius_list'         => '',
        ///'disc_center_opacity_list' => '0.5',
        ///'disc_center_color_list'   => 'red',
        ///'disc_border_width_list'   => '3',
        ///'disc_border_color_list'   => 'blue',
        ///'disc_border_opacity_list'  => '0.5',
        ///'disc_fill_color_list'      => 'lightblue',
        ///'disc_fill_opacity_list'    => '0.5'
        /// end discs
    
        if ($disc_center_list != ''){
          $centerListArray        = explode( ',', $disc_center_list );
          $radiusListArray        = explode( ',', $disc_radius_list );
          $centerOpacityListArray = explode( ',', $disc_center_opacity_list);
          $centerColorListArray   = explode( ',', $disc_center_color_list );
          $borderWidthListArray   = explode( ',', $disc_border_width_list );
          $borderColorListArray   = explode( ',', $disc_border_color_list );
          $borderOpacityListArray = explode( ',', $disc_border_opacity_list);
          $fillColorListArray     = explode( ',', $disc_fill_color_list );
          $fillOpacityListArray   = explode( ',', $disc_fill_opacity_list);
          $this->traceText(DEBUG_INFO, "(NumOfdiscs: ".sizeof($centerListArray)." NumOfradius: ".sizeof($radiusListArray).")!");
    
          if (sizeof($centerListArray) == sizeof($radiusListArray) && !empty($centerListArray) && !empty($radiusListArray)   ) {
            $output .= Osm_OpenLayers::addDiscs($centerListArray,$radiusListArray,$centerOpacityListArray,$centerColorListArray,
                                    $borderWidthListArray,$borderColorListArray,$borderOpacityListArray,$fillColorListArray,$fillOpacityListArray);
          } else {
            $this->traceText(DEBUG_ERROR, "Discs parameters error");
          }
        }
    
        /// end discs

    osm-openlayers.php

    /// discs
       function addDiscs($centerListArray,$radiusListArray,$centerOpacityListArray,$centerColorListArray,
                         $borderWidthListArray,$borderColorListArray,$borderOpacityListArray,$fillColorListArray,$fillOpacityListArray) {
    
       $layer='
       var discLayer = new OpenLayers.Layer.Vector("Disc Layer");';
    
       $layer.='
       addDisc = function (lon, lat, radius, centeropac, centercol, strw, strcol, stropac, fillcol, fillopac) {
       var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
    
        var discStyle    = { strokeColor: strcol,
                             strokeOpacity: stropac,
                             strokeWidth: strw,
                             fillColor: fillcol,
                             fillOpacity: fillopac
                           };
        var centerStyle  = { strokeColor: centercol,
                             strokeOpacity: centeropac,
                             strokeWidth: strw,
                             fillColor: centercol,
                             fillOpacity: centeropac
                           };
    
        var disc = OpenLayers.Geometry.Polygon.createRegularPolygon(
                                                 new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat),
                                                 radius,
                                                 200 // nombre de faces
                     );
        var center = OpenLayers.Geometry.Polygon.createRegularPolygon(
                                                 new OpenLayers.Geometry.Point(lonLat.lon, lonLat.lat),
                                                 1, // taille dans lunite de la carte
                                                 5  // nombre de faces
                     );
    
        var featureDisc   = new OpenLayers.Feature.Vector(disc,null,discStyle);
        var featureCenter = new OpenLayers.Feature.Vector(center,null,centerStyle);
        discLayer.addFeatures([featureDisc,featureCenter]);
       };
       ';
    
       for($i=0;$i<sizeof($centerListArray);$i++){
        // $centerListArray[$i] = lon lat -> lon,lat
        // only center and radius must be defined for each disc to be shown, else use first/default value (ie [0])
        $layer .= 'addDisc('.implode(",",explode( " ", trim($centerListArray[$i]) )).', '.$radiusListArray[$i].', '.
                          ((isset($centerOpacityListArray[$i]))? $centerOpacityListArray[$i] : $centerOpacityListArray[0]).', "'.
                          ((isset($centerColorListArray[$i]))?   $centerColorListArray[$i]   : $centerColorListArray[0]).'", '.
                          ((isset($borderWidthListArray[$i]))?   $borderWidthListArray[$i]   : $borderWidthListArray[0]).', "'.
                          ((isset($borderColorListArray[$i]))?   $borderColorListArray[$i]   : $borderColorListArray[0]).'", '.
                          ((isset($borderOpacityListArray[$i]))? $borderOpacityListArray[$i] : $borderOpacityListArray[0]).', "'.
                          ((isset($fillColorListArray[$i]))?     $fillColorListArray[$i]     : $fillColorListArray[0]).'", '.
                          ((isset($fillOpacityListArray[$i]))?   $fillOpacityListArray[$i]   : $fillOpacityListArray[0]).');
       ';
    
       }
       $layer.='
        map.addLayer(discLayer);';
    
        //$Layer='';
        return $layer;
       }
    
       /// end discs

    hope that can help
    alain

    http://wordpress.org/extend/plugins/osm/

  2. photoweblog
    Member
    Plugin Author

    Posted 11 months ago #

    Hi Alain,

    thanks for sharing your work!
    It's included in OSM plugin Version 2.0. You find a Beta Version at the WordPress OpenStreetMap Plugin OSM page. Let me know if you need any modifications to make it work with your page.
    Find a demonstration of the implementation on the WP OSM Example page.

    BR, MiKa

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic