Home > openlayers > problem in reading kml data in openlayers

problem in reading kml data in openlayers

October 4Hits:4
Advertisement

I am trying to read an KML file (point feature) and show it on a vector layer on OSM as the base map. My code seems to have a problem that does not show the features on the map. I don't now if its the problem with reading the data from KML file or is it related to visualizing it by Openlayers. Any help would be appreciated... Thanks!

My code:

<script src="http://www.openlayers.org/api/OpenLayers.js"></script>     <script>       function init() {         map = new OpenLayers.Map("map");         var mapnik         = new OpenLayers.Layer.OSM();         var fromProjection = new OpenLayers.Projection("EPSG:4326");   // Transform from WGS 1984         var toProjection   = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection         var position       = new OpenLayers.LonLat(48.69,31.345).transform( fromProjection, toProjection);         var zoom           = 12;          var layer = new OpenLayers.Layer.Vector("KML", {             strategies: [new OpenLayers.Strategy.Fixed()],             protocol: new OpenLayers.Protocol.HTTP({             url: "points.kml",             format: new OpenLayers.Format.KML()             })         });         map.addLayers([mapnik, layer]);         map.addControl(new OpenLayers.Control.LayerSwitcher());         map.setCenter(position, zoom );       } 

and my kml data:

<?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.2"> <Document> <name>Agencies test</name> <Folder> <name>BlahBlah!</name> <Placemark id="2"> <name>Something here!</name> <description>test</description> <LookAt> <longitude>49.69</longitude> <latitude>32.345</latitude> <altitude>0</altitude> <range>24.63686803544318</range> <tilt>0</tilt> <heading>1.387289180270979e-005</heading> </LookAt> <Point> <coordinates>49.69,32.345,0</coordinates> </Point> </Placemark> </Folder> </Document> </kml> 

Answers

Enable web developer extensions and post a better error report - what shows up in the console - please.

I kind of have a hunch that if you loose the fromProjection and toProjection definitions for your map it will display fine. Last week I tried to force the projections as well together with a KML file as data source and it only worked (and displayed fine) when I removed any explicit projection attributes. Just hinting, might be worth a try (I use latest openlayers release from git repo).

another thing you could try on the kml layer itself is set the projection as such:

        projection: map.displayProjection

Keep the info coming.

Your data needs to be in a Geographic xml-formatted format. e.g. - KML or GeoRSS or WFS. Openalyers.Format.XML is really there as a helper class to read generic XML files, so you can't use it as a Layer Format on the map. And then add the layer to your map with that specific format (again... KML or GeoRSS...)

Your code works fine for me. Simply zoom out to view your KML point.

The problem is your point in the KML is at 49.69,32.345 but the position you are zooming in on is at 48.69,31.345.

problem in reading kml data in openlayers

Tags:xml, openlayers

Related Articles

  • problem in reading kml data in openlayers

    problem in reading kml data in openlayersOctober 4

    I am trying to read an KML file (point feature) and show it on a vector layer on OSM as the base map. My code seems to have a problem that does not show the features on the map. I don't now if its the problem with reading the data from KML file or is

  • Openlayers draw multiple coordinates off KML data coming from the databaseJanuary 17

    I am a pure beginner of openlayers, I have a KML data coming from the database which describes all the cordinates of zip code 45050, I would like to draw these coordinates onto openlayers map as boundaries and I want it colored as well. I am not pret

  • Problem importing KML file to OpenLayers - Projection SystemDecember 8

    I know that many have this problem,but none of the answers helped me so i suppose it's a different problem.This is my code: <!DOCTYPE html> <html> <head> <title>Lesson Javascript-OpenLayers-WMS</title> <script src="ht

  • How to dynamically update a KML layer in OpenLayers 2.10?July 26

    Arguably, this is a easy question for you guys GIS expert. Here is the question, how to outsource a dynamic KML file using JavaScript in OpenLayers. I want to refresh every 7 seconds. Below are snippet of the given codes: <script type='text/javascrip

  • Are there sources for obtaining pre-made KML data from Google?June 7

    I have been asked to investigate methods for obtaining KML files. All I know so far is that it is a format based on XML that Google uses to format their maps (or the metadata). However, are there places or methods that I may avail myself of to downlo

  • How to add KML data but from variable - not from url?November 7

    I have a working map that retrieves KML from a url, but now I need to get the KML data from a local variable instead. Is there support for this, and if so what is the syntax. Searched the api and various sites but no luck finding anything about this.

  • Filtering a loaded kml file in OpenLayersJune 25

    I'm trying to create an interactive search engine (for finding event tickets) of which one of its features is a visual map that shows related venues using OpenLayers. I have a plethora of venues (3000+) in a kml file that I would like to selectively

  • How to create KML file with OpenLayers?August 17

    I try to create kml file from features. My code var feature=myVecLayer.getFeatureByFid('filedata.1'); var format; function GetKMLFromFeatures(feature) { format = new OpenLayers.Format.KML({ 'maxDepth':10, 'extractStyles':true, 'internalProjection': n

  • Trying to display some data in OpenLayers - it's not erroring, just not loading :(

    Trying to display some data in OpenLayers - it's not erroring, just not loading :(May 22

    I'm trying to display some KML data on a map, using OpenLayers. Nothing complex - but it's just not rendering. Here's my javascript code var map; function init(element, kml) { map = new OpenLayers.Map(element, { projection: 'EPSG:3857', layers: [ new

  • Displaying real-time CSV data in OpenLayers 3?January 28

    is there a good way to display real-time csv data with OpenLayers 3? http://geofon.gfz-potsdam.de/eqinfo/list.php?datemin=&datemax=&latmin=&latmax=&lonmin=&lonmax=&magmin=&fmt=html&nmax=10&fmt=csv ol2 had the opportunit

  • How can I transform some KML data to Sql Server 2008 using FME?December 14

    I've just downloaded FME 14 day trial. I'm trying to see how easy/hard it is to transform some KML data (a simple neighbourhood shape) into my Sql Server 2008 database using FME. I sorta don't even know where to start .. blush. The closest I got was

  • How to cluster kml features in OpenLayersJuly 3

    Is it possible to cluster KML features in OpenLayers, and are there any samples? I can find separate samples for clusters and KML but nothing which handles both together. Thanks --------------Solutions------------- It's definitely possible. Add your

  • How to highlight kml features in openlayersDecember 12

    I'm trying to make the features from a kml layer highlight on hover, but it doesn't seem to work for me. On the other hand, if i create a vector layer with a polygon feature it works just fine. I made an example with kml and polygon feature just to t

  • Problem viewing SQL 2008 "Date" fieldMay 30

    I am using ArcMap Basic 10.1 SP1 and I'm connected to a permitting database stored in a SQL Server 2008 R2 database. I am trying to pull the tabular data over into my ArcGIS Desktop Project so that I can do a join with the permit boundary information

  • Unable to style KML layer in OpenLayers 3January 22

    I have KML data, which looks like this: <?xml version="1.0" encoding="utf-8" ?> <kml xmlns="http://www.opengis.net/kml/2.2"> <Document><Folder><name>City</name> <Schema name="City&q

  • A Java program that will data KML data from a folderFebruary 5

    I want to write a program that will take KML data from a folder and displace it on Google map and some other global map and continue update this data. I don't know what part of Java I need to use to do this. Please help me out.

  • Problems adding KML layer in OpenLayersJuly 9

    I'm stuggling to add a KML layer to a simple test OpenLayers map - no errors are shown, but the KML layer does not display on the map. I've tried multiple samples including the Sundials on a Spherical Mercator sample and the Layers help page. I can o

  • How to register onclick handler for *all* KML feaures in OpenLayers?January 18

    I'm a newbie using OpenLayers with JQuery to display vector data from KML files. I'm creating the layer like this: newlayer = new OpenLayers.Layer.Vector( layerid, { projection: MAPVAR.displayProjection, strategies: [new OpenLayers.Strategy.Fixed()],

  • Best way to animate radar data in openlayersFebruary 23

    I have a project using OpenLayers which displays radar data on a map. The radar data itself is just a bunch of polygons each of which is filled with one of 6 possible colors. The goal is to animate the radar on the map. Each file contains radar data

  • Layer misalignment with UK Ordnance Survey data and OpenLayersMay 11

    I am in the UK and my QGIS projects are based on UK Ordnance Survey mapping data and are set up in EPSG:27700. Whenever I have tried dropping an OpenLayers layer (Google Satellite/Bing Maps Aerial) in via the OpenLayers plugin (v0.90) it is always of

Copyright (C) 2017 ceus-now.com, All Rights Reserved. webmaster#ceus-now.com 14 q. 0.780 s.