I am developing using MapWinGIS5
I have been successful somehow. I want to port some c# code into may package and I have issues. I have check the net for solutions but yet to find any. I have two code variants here:
void CGISView::MarkPoints()
{
m_map.put_Projection((long)tkMapProjection::PROJECTION_GOOGLE_MERCATOR);
IShapefilePtr sf;
HRESULT hResult = sf.CreateInstance(CLSID_Shapefile);
::CoInitialize(NULL);
CString filename = OpenLayerFile(false);// dataPath + points.shp";
MapWinGIS::IShapefile *sff = nullptr;
sf->QueryInterface(IID_IShapefile, (void**)&sff);
if (sff == nullptr)
{
return;
}
USES_CONVERSION;
VARIANT_BOOL retVal = true;
hResult = sff->Open(A2W(filename), nullptr, &retVal);
retVal = true;
m_layerHandle = m_map.AddLayer(sff, true); // in case a copy of shapefile was created by GlobalSettings.ReprojectLayersOnAdding
retVal = true;
if (!sff->CreateNewWithShapeID(A2W(""), MapWinGIS::ShpfileType::SHP_POINT, &retVal))
{
long errorCode;
hResult = sf->get_LastErrorCode(&errorCode);
BSTR errorMessage;
sf->get_ErrorMsg(errorCode, &errorMessage);
CString serror(errorMessage);
AfxMessageBox("Failed to create shapefile: " + serror + " " + filename);// + sf.ErrorMsg[sf.LastErrorCode]);
return;
}
m_layerHandle = m_map.AddLayer(sff, true); // in case a copy of shapefile was created by GlobalSettings.ReprojectLayersOnAdding
#pragma region DrawingOptions
VARIANT_BOOL doptionsFlag = true;
IShapeDrawingOptionsPtr options;
options.CreateInstance(__uuidof(ShapeDrawingOptions));
hResult = sf->get_DefaultDrawingOptions(&options);
options->put_DynamicVisibility(doptionsFlag);
options->put_FrameType(tkLabelFrameType::lfRectangle);
options->put_Picture(OpenMarker("HelpFiles\\Icons\\marker.png"));
options->put_PointType(tkPointSymbolType::ptSymbolPicture);
sf->put_CollisionMode(tkCollisionMode::AllowCollisions);
sf->put_DefaultDrawingOptions(options);
#pragma endregion
m_map.SetCursorMode((long)MapWinGIS::tkCursorMode::cmNone);
m_map.put_TrapRMouseDown(true);
AxMap1MouseDownEvent; // change MapEvents to axMap1
}
For the code above, all hResult alway give 0. That is none is working
sf->QueryInterface( ) is saying object not set to instance…
For the second variant, I use CShapefile from the type library:
< Blockquote
void CGISView::MarkPoints2()
{
m_map.put_Projection((long)tkMapProjection::PROJECTION_GOOGLE_MERCATOR);
LPDISPATCH lDispatch = NULL;
CShapefile *sf = new CShapefile(lDispatch);
CString filename = OpenLayerFile(false);// dataPath + "points.shp";
USES_CONVERSION;
BOOL hResult = sf->Open(filename, nullptr);
> MapWinGIS::IShapefile *sff = nullptr;
> lDispatch->QueryInterface(CLSID_Shapefile, (void**)&sff);
> if (sff == nullptr)
> {
> return;
> }
> m_layerHandle = m_map.AddLayer(sff, true); // in case a copy of shapefile was created by GlobalSettings.ReprojectLayersOnAdding
> if (!sff->CreateNewWithShapeID("", MapWinGIS::ShpfileType::SHP_POINT))
> {
> long errorCode = sf->get_LastErrorCode();
> CString errorMessage = sff->get_ErrorMsg(errorCode);
> AfxMessageBox("Failed to create shapefile: " + errorMessage + " " + filename);// + sff.ErrorMsg[sff.LastErrorCode]);
> return;
> }
> m_layerHandle = m_map.AddLayer(sff, true); // in case a copy of shapefile was created by GlobalSettings.ReprojectLayersOnAdding
>
> #pragma region DrawingOptions
> VARIANT_BOOL doptionsFlag = true;
> IShapeDrawingOptionsPtr options;
> options.CreateInstance(__uuidof(ShapeDrawingOptions));
> options = sf->get_DefaultDrawingOptions();
> options->put_DynamicVisibility(doptionsFlag);
> options->put_FrameType(tkLabelFrameType::lfRectangle);
> options->put_Picture(OpenMarker("HelpFiles\\Icons\\marker.png"));
> options->put_PointType(tkPointSymbolType::ptSymbolPicture);
> sf->put_CollisionMode(tkCollisionMode::AllowCollisions);
> sf->put_DefaultDrawingOptions(options);
> #pragma endregion
> m_map.SetCursorMode((long)MapWinGIS::tkCursorMode::cmNone);
> m_map.put_TrapRMouseDown(true);
> }
My main issue in the second code option is passing (CShapefile)sf as LPDISPATCH object to m_map.AddLayer();
I want people who use MFC here to help.
Thank you.
Kehinde IsijolaPreformatted text