AW: [OpenLayers-Users] Re: Reading KML file into multiple layers

Arnd Wippermann arnd.wippermann at web.de
Sat Apr 23 18:00:16 EDT 2011


Hi,

If you want to have points and lines on an own layer you can try

1. create two layers to read the same kml file
2. add an own parameter to your layers (geom:"OpenLayers.Geometry.Point" or
geom:"OpenLayers.Geometry.Point" )
3. register beforefeatureadded for the layers, where you separate the
feature by geometryType

...
var kmlLines = new OpenLayers.Layer.Vector("KML tracks", {
    geom:"OpenLayers.Geometry.LineString",
    protocol: new OpenLayers.Protocol.HTTP({
        url: "test.kml",
        format: new OpenLayers.Format.KML({extractStyles: false,
extractAttributes: true})
    }),
    strategies: [new OpenLayers.Strategy.Fixed()],
    style: {fillColor: "red", strokeColor: "blue", strokeWidth: 4,
strokeOpacity: 0.5, pointRadius: 5},
    projection: new OpenLayers.Projection("EPSG:4326")
});

kmlPoints.events.register("beforefeatureadded", kmlPoints, function (obj) {
return( addFeatureByGeometry(obj, this));});
kmlLines.events.register("beforefeatureadded", kmlLines,   function (obj) {
return( addFeatureByGeometry(obj, this));});

...

function addFeatureByGeometry(obj, lyr)
{
    if(obj.feature.geometry.CLASS_NAME==lyr.geom)
        return true;
    else
        return false;
}

>From Layer\Vector.js

     * Supported map event types (in addition to those from
<OpenLayers.Layer>):
     * beforefeatureadded - Triggered before a feature is added.  Listeners
     *      will receive an object with a *feature* property referencing the
     *      feature to be added.  To stop the feature from being added, a
     *      listener should return false.

This way you can separate the feature also by given attributes.

Arnd


-----Ursprüngliche Nachricht-----
Von: openlayers-users-bounces at lists.osgeo.org
[mailto:openlayers-users-bounces at lists.osgeo.org] Im Auftrag von Yerry
Gesendet: Samstag, 23. April 2011 20:46
An: users at openlayers.org
Betreff: [OpenLayers-Users] Re: Reading KML file into multiple layers

The pre condition is that I have a KML file which contains both Placemarks
and Track(s).

It is no option to seperate it into multiple files.

Is there no way to extract portions, or let generate multiple layers from
one KML?

Thanks for your help.

--
View this message in context:
http://osgeo-org.1803224.n2.nabble.com/Reading-KML-file-into-multiple-layers
-tp6293353p6299927.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
Users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/openlayers-users



More information about the Users mailing list