Fusion custom widget: how to proceed

View: New views
7 Messages — Rating Filter:   Alert me  

Fusion custom widget: how to proceed

by gingerbbm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Dear all

I'm new to MapGuide and Fusion. We have an Enterprise 2009 (Windows, IIS) set-up here and I've successfully created a simple page showing a map and toolbar. I now want to create a custom widget that allows the user to define a polygon which is then converted to a redline object on the map.

The Developer's Guide is fairly helpful, stating the three main steps involved in redlining:
1. Pass the digitized coordinates from the client to the server.
2. Create a temporary feature source. This will be used to draw the lines on.
3. Create a layer to display that temporary feature source.

But I'm stuck at 1.

I took a copy of SelectPolygon.js, renamed it to DrawPolygon.js, and found out where to grab the drawn vertices, but I'm not sure how best to fire this at a PHP file.

I'd appreciate any comments on the best way to do this, and any pointers to examples.

Many thanks
Stuart

Re: Fusion custom widget: how to proceed

by Mike Adair :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Examples of calling server-side PHP can be found in
MapGuide/MapGuide.js.  Look for 'Fusion.ajaxRequest' which essentially
maps to OpenLayers.Ajax.Request with the Fusion URL prepended (in
lib/fusion.js).

Mike

gingerbbm wrote:

> Dear all
>
> I'm new to MapGuide and Fusion. We have an Enterprise 2009 (Windows, IIS)
> set-up here and I've successfully created a simple page showing a map and
> toolbar. I now want to create a custom widget that allows the user to define
> a polygon which is then converted to a redline object on the map.
>
> The Developer's Guide is fairly helpful, stating the three main steps
> involved in redlining:
> 1. Pass the digitized coordinates from the client to the server.
> 2. Create a temporary feature source. This will be used to draw the lines
> on.
> 3. Create a layer to display that temporary feature source.
>
> But I'm stuck at 1.
>
> I took a copy of SelectPolygon.js, renamed it to DrawPolygon.js, and found
> out where to grab the drawn vertices, but I'm not sure how best to fire this
> at a PHP file.
>
> I'd appreciate any comments on the best way to do this, and any pointers to
> examples.
>
> Many thanks
> Stuart
>  
_______________________________________________
mapguide-users mailing list
mapguide-users@...
http://lists.osgeo.org/mailman/listinfo/mapguide-users

Re: Fusion custom widget: how to proceed

by gingerbbm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Mike Adair wrote:
Examples of calling server-side PHP can be found in
MapGuide/MapGuide.js.  Look for 'Fusion.ajaxRequest'
Thanks Mike. Ended up using measureSegment() from the Measure widget as my basis.

Re: Fusion custom widget: how to proceed

by gingerbbm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm struggling with this. I think part of the problem is that I've been trying to use the redlining example (PHPSAMPLES/DIGITIZING_FEATURES/draw_line.php) in the creation of a Fusion widget. Not to mention the fact that this is my first time with the MapGuide API and I'm not sure conceptually what the steps are to add a custom geometry to a map.

Where I'm at is that the JavaScript behind my DrawPolygon widget is calling the PHP I've written (based on the aforementioned "draw_line.php"). I assume that the PHP code is OK (it doesn't error) but how do I get the map to refresh once the PHP code has executed?

Re: Fusion custom widget: how to proceed

by gingerbbm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've now taken the SelectPolygon widget as the basis for my new DrawPolygon tool. I have created duplicates of the functions in fusion\MapGuide\MapGuide.js such as query(), processQueryResults() and so on and tweaked them to call my PHP function.

The whole process completes without error: I draw a polygon, the PHP is called, and the map refreshes. But my geometry doesn't appear. What am I missing?

The PHP code is definitely creating a new layer. But I'm not seeing this in the "this.aLayers" collection in the JavaScript. Should I? How do I show my new layer?

Re: Fusion custom widget: how to proceed

by gingerbbm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have now replaced "this.drawMap()" with "this.reloadMap()" in the JavaScript and my new layer is now present in the aLayers collection. But it still doesn't show on the map.

How can I check that the layer I've generated really does contain the polygon that I think (and hope) it does?

Re: Fusion custom widget: Add polygon to layer

by gingerbbm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

gingerbbm wrote:
How can I check that the layer I've generated really does contain the polygon that I think (and hope) it does?
To answer my own question, you need to use the SchemaReport feature of the MapAgent, available at:

http://{server}/{mapguide2009}/schemareport/main.php

Into the "Resource ID" textbox type the following:

Session:{Session ID}//{New layer name}.FeatureSource

Click "Find". On the next screen, click "View Feature" to see if your polygon (or whatever) exists.

In my case, I discovered that the polygon wasn't being created despite receiving no error messages. It turns out that [using the DRAW_LINES.PHP from the MapGuide samples] the string "Lines" in the following code excerpt must be consistent.

...
$map = new MgMap();
$map->Open($resourceService, $mapName);    
$layerName = "Lines";
...
$classDefinition = new MgClassDefinition();
$classDefinition->SetName("Lines");
...
$featureName = "SHP_Schema:Lines";
$geometry = "SHPGEOM";
$layerDefinition = $factory->CreateLayerDefinition(...);
...

Hope this helps somebody someday...

Cheers
Stuart
LightInTheBox - Buy quality products at wholesale price