[mapguide-users] Fwd: download kml and upload kml in fusion

Hadis Alinia hadissaalinia at gmail.com
Sat Jun 4 14:43:51 PDT 2022


Thank you for your email.

I did the same. First, I got the error "the kml is not defined in the
openlayer 2.13" then I received no error message, but I still cannot see
the kml map.
Even I added a code to my taskpane.html. Enable user to select the file
from their local machine and add kml but again no error and no map. below
is my code leveraged the map difinition from your code:

I also added the below script to use openlayer version 3.5.0

 <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
    <link rel="stylesheet" href="
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <script src="
https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js
"></script>
    <link rel="stylesheet" href="
https://cdnjs.cloudflare.com/ajax/libs/ol3/3.5.0/ol.css" type="text/css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ol3/3.5.0/ol.js
"></script>

function addKML() {


    var map = parent.Fusion.getMapById('Map');
    var projection = ol.proj.get('EPSG:3857');

    var file = window.document.getElementById("selectfile").files[0];
    if (file) {

      var reader = new FileReader();
      reader.onload = function () {

        var vector = new ol.layer.Vector({
          source: new ol.source.Vector({

            url: reader.result,
            format: new ol.format.KML()
<!-- extractStyles: true, -->
            <!-- extractAttributes: true, -->
<!-- maxDepth: 2, -->
  <!-- internalProjection: "EPSG:3857", -->
            <!-- externalProjection: "EPSG:4326" -->
<!-- }), -->
<!-- visible: true -->
          })

        });


       //vector.transform(srcProj, dest);
        parent.Fusion.getMapById('Map').oMapOL.addLayers(vector);

      }
      reader.readAsDataURL(file);

    }

  }

<body>

<input id="selectfile" type="file" accept=".kml" onchange="addKML()">

<div id="info"> </div>
 </body>

Please let me know what I am doing wrong?

Thanks
HA




On Mon, May 30, 2022 at 2:39 PM Gordon Luckett <
gordon.luckett at arrowgeomatics.com> wrote:

> For KML, you might have to do a number of things:
>
> 1. Add KML to your IIS Mime Type (i.e. ."kml" / "application/vnd" )
> 2. Add the KML Type to OpenLayers (2.13.1)
> https://cdnjs.cloudflare.com/ajax/libs/openlayers/*2.13.1*/lib/OpenLayers/Format/KML.js
> because this format is not bundled with the MapGuide 3.1.2 or 4 versions
>
>
>
> for example, I added this to my maroon index.templ
>
> <script type="text/javascript"
> src="%__LIB_BASE__%/%__FUSION_SCRIPT__%.js"></script>
> %__SCRIPTS__%
> *<script
> src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/lib/OpenLayers/Format/KML.js
> <https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/lib/OpenLayers/Format/KML.js>"></script>*
>
>
>
>  then added the following code to the "initPanelHandler" function:
>
> var layer = new OpenLayers.Layer.Vector("KML", {
>             strategies: [new OpenLayers.Strategy.Fixed()],
>             protocol: new OpenLayers.Protocol.HTTP({
>                 url: "kml/lines.kml",
>                 format: new OpenLayers.Format.KML({
>                     extractStyles: true,
>                     extractAttributes: true,
>                     maxDepth: 2
>                 })
>             })
>         });
> Fusion.getMapById('Map').oMapOL.addLayer(layer);
>
> and I had success adding KML to my Maroon Template...
>
>
>
>
>
> On Mon, May 30, 2022 at 9:33 AM Hadis Alinia <hadissaalinia at gmail.com>
> wrote:
>
>> Does anyone have any idea why I can't see my kml file? Do you have any
>> sample code that works for you?
>>
>> ---------- Forwarded message ---------
>> From: Hadis Alinia <hadissaalinia at gmail.com>
>> Date: Thu, May 26, 2022 at 9:27 AM
>> Subject: Re: [mapguide-users] download kml and upload kml in fusion
>> To: MapGuide Users Mail List <mapguide-users at lists.osgeo.org>
>>
>>
>> Hi Gordon,
>>
>> I am trying to script to upload a kml from local folder to my map. (I
>> want the user to select the file from their local folder and be able to
>> overlay (temporary) on the other exiting maps)
>> I placed a kml sample into my template folder and added a script to task
>> pane as follows : I don't receive any error, but I can't see my map. I am
>> not sure what is the issue?
>>
>>
>> var source = new Proj4js.Proj('EPSG:4326');
>> Proj4js.defs["EPSG:3857"]="+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0
>> +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs"
>> var dest = new Proj4js.Proj('EPSG:3857');
>>
>> var geocoder = new google.maps.Geocoder();
>>
>> function display_kmlmap()
>> {
>>
>> var map = parent.Fusion.getWidgetById('Map');
>> var olMap = map.oMapOL;
>>
>>
>> var kmlmap = new parent.OpenLayers.Layer.vector("KML", "KML/sample.kml", {
>>    format: parent.OpenLayers.Format.KML,
>>    projection:  new parent.OpenLayers.Projection('EPSG:3857'),
>>    formatOptions: {
>>        'extractStyles': true,
>>    'extractAttributes': true
>>    },
>>    visible: true
>> });
>>
>> olMap.addLayers(kmlmap);
>>
>> <body onload="display_kmlmap()">
>>
>>
>>     <div id="map" class="smallmap"></div>
>>
>> </body>
>>
>>
>>
>> On Wed, May 18, 2022 at 11:48 AM Gordon Luckett <
>> gordon.luckett at arrowgeomatics.com> wrote:
>>
>>> Ajax (Basic Web Layout) does not support KML - the Fusion (Flexible Web
>>> Layout/Web Application) uses OpenLayers 2.13 and this does support KML
>>> parsing etc.
>>>
>>>
>>>
>>>
>>>
>>> On Tue, May 17, 2022 at 7:07 PM Hadis Alinia <hadissaalinia at gmail.com>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> I need to enable the user of my webmap application built by Mapguide to
>>>> overlay their kml layers in ajax view or convert CSVs with lat and lon to a
>>>> point data and then can download their points data as kml. Or select a
>>>> feature of the uploaded layer and download it as a kml. Is that even
>>>> possible in mapguide? I can't find an example searching on google.
>>>> Please advise
>>>>
>>>> Thank you
>>>> HA
>>>> _______________________________________________
>>>> mapguide-users mailing list
>>>> mapguide-users at lists.osgeo.org
>>>> https://lists.osgeo.org/mailman/listinfo/mapguide-users
>>>>
>>> _______________________________________________
>>> mapguide-users mailing list
>>> mapguide-users at lists.osgeo.org
>>> https://lists.osgeo.org/mailman/listinfo/mapguide-users
>>>
>> _______________________________________________
>> mapguide-users mailing list
>> mapguide-users at lists.osgeo.org
>> https://lists.osgeo.org/mailman/listinfo/mapguide-users
>>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/mapguide-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/mapguide-users/attachments/20220604/ed3bc09a/attachment.htm>


More information about the mapguide-users mailing list