[fusion-users] Re: Show Layer added in MapScript
Paul Deschamps
pdeschamps at dmsolutions.ca
Wed Mar 24 14:49:01 EDT 2010
Here's a couple func's i've used in the past:
function addPoint($oMap,$szName,$x,$y,$szSymbolName,$aColor1,$aColor2){
// create layer
$layer = ms_newLayerObj($oMap);
$layer->set("name",$szName);
$layer->set("status",MS_DEFAULT);
$layer->set("type",MS_LAYER_POINT);
// create class
$class = ms_newClassObj($layer);
$class->set("name",$szName);
// set style
$style = ms_newStyleObj($class);
$style->set('symbolname',$szSymbolName);
$style->set('size',12);
$style->set('angle',0);
$style->set('width',4);
$style->color->setRGB($aColor1[0],$aColor1[1],$aColor1[2]);
$style->outlinecolor->setRGB($aColor2[0],$aColor2[1],$aColor2[2]);
// add lines / points to shape
if ($x != "" && $y != ""){
$shape = ms_newShapeObj(MS_SHAPE_POINT);
$oLine = ms_newLineObj();
$oLine->addXY($x,$y);
$shape->add($oLine);
$layer->addFeature($shape);
}
return $oMap;
}
function addPolygonFeatureToMap($oMap, $polygon_coordinates, $label,$oRGB){
// create layer
$layer = ms_newLayerObj($oMap);
$layer->set("name","POLY_".$label);
$layer->set("status",MS_DEFAULT);
$layer->set("type",MS_LAYER_POLYGON);
// create class
$class = ms_newClassObj($layer);
$class->set("name",$label);
// set style
$style = ms_newStyleObj($class);
$outlineColor = $oRGB->outline;
$fillColor = $oRGB->color;
$style->color->setRGB($fillColor->r,$fillColor->g,$fillColor->b);
$style->outlinecolor->setRGB($outlineColor->r,$outlineColor->g,$outlineColor->b);
// add points
$line = ms_newLineObj();
foreach ($polygon_coordinates as $record){
$point = ms_newPointObj();
$x = $record->x;
$y = $record->y;
$point->setXY($x,$y);
$line->add($point);
}
// add the first point again to close the polygon
if(count($polygon_coordinates) > 2){
$point = ms_newPointObj();
$x = $polygon_coordinates[0]->x;
$y = $polygon_coordinates[0]->y;
$point->setXY($x,$y);
$line->add($point);
}
// add lines / points to shape
$shape = ms_newShapeObj(MS_SHAPE_POLYGON);
$shape->set("classindex", 0);
$shape->add($line);
$layer->addFeature($shape);
return $oMap;
}
Hope this helps
Cheers
Paul D.
On Wed, Mar 24, 2010 at 1:27 PM, millsde <millsde at dfo-mpo.gc.ca> wrote:
>
> I'm adding a point to the map instead of a layer. I tried doing what you
> suggested(or at least I think I am) for the past week now, but cannot get
> the updated map to show up in the fusion window. Although if I save the
> image( using $image->saveWebImage() ) the point displays correctly. Can you
> see what I'm doing wrong in my code snip-it?
>
> javascript code ---------------------------------------------------
> .
> .
> .
> handler: function(button) {
> if (button == 'Add') {
> var lat = this.dialog.getValue('Latitude');
> var longit = this.dialog.getValue('Longitude');
> var map = Fusion.getMapByIndice(0);
>
> var session = 'session='+map.getSessionID();
> var mapName = '&mapname='+ map.getMapName();
> var latparam = '&latitude='+lat;
> var longparam = '&longitude='+longit;
> var params = session+mapName+latparam+longparam;
>
> var options = {parameters:params, onSuccess:
> this.APResults.bind(this)};
> new Ajax.Request(this.queryURL, options);
>
> }
>
> this.dialog.close();
> },
>
> APResults: function(r) {
>
> var mainMap = this.getMap();
> var aMaps = mainMap.getAllMaps();
> parent.document.getElementById('Map').widget.aMaps[0].reloadMap();
>
> }
>
>
> php code -----------------------------------------------------
> .
> .
> .
> if ( ($_REQUEST["latitude"] != "") && ($_REQUEST["longitude"] != "")) {
> $lat = $_REQUEST["latitude"];
> $longit = $_REQUEST["longitude"];
> }
> else {
> die('Error: Lat/Long not set');
> }
>
> if (isset($_SESSION['maps']) && isset($_SESSION['maps'][$mapName])) {
> $map = ms_newMapObj($_SESSION['maps'][$mapName]);
> }
> else {
> die('Error: Map not set');
> }
>
> $pLayer = ms_newLayerObj($map);
> $pLayer->set("name", "New Point");
> $pLayer->set("type", MS_LAYER_POINT);
> $pLayer->set("status", MS_ON);
> $class = ms_newClassObj($pLayer);
> $style = ms_newStyleObj($class);
> $style->color->setRGB(255,0,0);
> $style->set("symbolname", "circle");
> $style->set("size", 10);
> $my_point = ms_newpointObj();
> $my_point->setXY($lat, $longit);
> $image=$map->draw();
> $my_point->draw( $map, $pLayer, $image, 0, "New Point" );
>
> /*$image_url=$image->saveWebImage();
> echo " $image_url "; */
> $map->save($_SESSION['maps'][$mapName]);
>
> --------------------------------------------------------------------
> --
> View this message in context: http://n2.nabble.com/Show-Layer-added-in-MapScript-tp4716387p4792497.html
> Sent from the Fusion Users mailing list archive at Nabble.com.
> _______________________________________________
> fusion-users mailing list
> fusion-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/fusion-users
>
--
Paul Deschamps
Applications Specialist
DM Solutions Group Inc.
Office: (613) 565-5056 x28
pdeschamps at dmsolutions.ca
http://www.dmsolutions.ca
http://research.dmsolutions.ca
More information about the fusion-users
mailing list